-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_flags.c
38 lines (34 loc) · 709 Bytes
/
get_flags.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "main.h"
/**
* get_flags - Function that calculates active flags
* @format: Formatted string in which to print the arguments
* @i: take a parameter.
*
* Return: Flags
*/
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);
}