-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_getspecificator.c
More file actions
67 lines (62 loc) · 2.24 KB
/
ft_getspecificator.c
File metadata and controls
67 lines (62 loc) · 2.24 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_getspecificator.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbalon-s <mbalon-s@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/23 17:33:46 by mbalon-s #+# #+# */
/* Updated: 2019/03/02 22:01:24 by mbalon-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
#include <stdlib.h>
static size_t additional_getspecificator(const char *format,
t_specification *pspec)
{
size_t res;
res = 1;
if (*format == '%')
pspec->specificator = PERCENT;
else if (*format == 'p')
pspec->specificator = POINTER;
else if (*format == 'a')
pspec->specificator = A_FLOAT;
else if (*format == 'A')
pspec->specificator = A_FLOAT_UPPER;
else if (*format == 'f')
pspec->specificator = FLOAT;
else
{
pspec->specificator = UNKNOWN;
pspec->ch = *format;
return (*format == '\0' ? 0 : 1);
}
return (res);
}
size_t ft_getspecificator(const char *format,
t_specification *pspec)
{
size_t res;
res = 1;
if (*format == 'c' || *format == 'C')
pspec->specificator = CHAR;
else if (*format == 's' || *format == 'S')
pspec->specificator = STRING;
else if (*format == 'd' || *format == 'i' || *format == 'D')
pspec->specificator = INTEGER;
else if (*format == 'o' || *format == 'O')
pspec->specificator = OCT;
else if (*format == 'x')
pspec->specificator = HEX;
else if (*format == 'X')
pspec->specificator = HEX_UPPER;
else if (*format == 'u' || *format == 'U')
pspec->specificator = UNSIGNED;
else
return (additional_getspecificator(format, pspec));
if (*format == 'D' || *format == 'O' ||
*format == 'U' || *format == 'C' || *format == 'S')
pspec->long_long_mod = 1;
return (res);
}