forked from kbtisuu/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
godswillubah
committed
Mar 28, 2023
1 parent
13e1b59
commit 168a838
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* get_flags - Calculates active flags | ||
* @format: Formatted string in which to print the arguments | ||
* @i: take a parameter. | ||
* Return: Flags: | ||
* Written by Kebron Araya and Godswill Ubah. | ||
int get_flags(const char *format, int *i) | ||
{ | ||
/* - + 0 # ' ' */ | ||
/* 1 2 4 8 16 */ | ||
int j, curr_i; | ||
int flags = 0; | ||
const char FLAGS_CH[] = {'-', '+', '0', '#', ' ', '\0'}; | ||
const int FLAGS_ARR[] = {F_MINUS, F_PLUS, F_ZERO, F_HASH, F_SPACE, 0}; | ||
|
||
for (curr_i = *i + 1; format[curr_i] != '\0'; curr_i++) | ||
{ | ||
for (j = 0; FLAGS_CH[j] != '\0'; j++) | ||
if (format[curr_i] == FLAGS_CH[j]) | ||
{ | ||
flags |= FLAGS_ARR[j]; | ||
break; | ||
} | ||
|
||
if (FLAGS_CH[j] == 0) | ||
break; | ||
} | ||
|
||
*i = curr_i - 1; | ||
|
||
return (flags); | ||
} |