-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_flags.c
More file actions
36 lines (31 loc) · 791 Bytes
/
get_flags.c
File metadata and controls
36 lines (31 loc) · 791 Bytes
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
#include "main.h"
/**
* get_flag - turns on flags if _printf finds
* a flag modifier in the format string
* @s: character that holds the flag specifier
* @f: pointer to the struct flags in which we turn the flags on
*
* Return: 1 if a flag has been turned on, 0 otherwise
*/
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);
}