-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetformat.c
More file actions
49 lines (46 loc) · 1011 Bytes
/
getformat.c
File metadata and controls
49 lines (46 loc) · 1011 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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "holberton.h"
/**
* getformat - get the char after the %
* @c: the string
* @pos: position of format
*
* Return: Option contain the char after %
* 0 if fails
*/
options getformat(const char *c, int *pos)
{
int i = *pos;
options op;
op.precision = 0;
for (; c[i]; i++)
{
if (c[i + 1] > '0' && c[i + 1] <= '9')
op.precision = op.precision + c[i + 1] - 48;
if (c[i + 1] == '-')
op.signn = 1;
if (c[i + 1] == '+')
op.signp = 1;
if (c[i + 1] == ' ')
op.spc = 1;
if (c[i + 1] == '0')
op.zeros = 1;
if (c[i + 1] == '#')
op.hash = 1;
if (c[i + 1] == '.')
op.point = 1;
if (c[i + 1] == 'l')
op.longer = 1;
if (c[i + 1] == 'h')
op.sh = 1;
if ((c[i + 1] > '0' && c[i + 1] <= '9') || c[i + 1] == '-'
|| c[i + 1] == '+' || c[i + 1] == ' ' || c[i + 1] == '0'
|| c[i + 1] == '#' || c[i + 1] == '.' || c[i + 1] == 'l'
|| c[i + 1] == 'h')
continue;
*pos = i + 1;
op.type = c[i + 1];
return (op);
}
op.type = 0;
return (op);
}