-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_type.c
More file actions
58 lines (51 loc) · 1.78 KB
/
ft_type.c
File metadata and controls
58 lines (51 loc) · 1.78 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: slepetit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/28 14:54:10 by slepetit #+# #+# */
/* Updated: 2022/04/28 22:35:49 by slepetit ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_check_s(va_list li)
{
char *tmp;
tmp = va_arg(li, char *);
if (tmp == NULL)
return (ft_putstr("(null)"));
else
return (ft_putstr(tmp));
}
int ft_check_p(va_list li)
{
long int nb;
nb = va_arg(li, long int);
if (nb == 0)
return (ft_putstr("(nil)"));
else
return (ft_putptr(nb));
}
size_t ft_type(char type, va_list li)
{
size_t i;
i = 0;
if (type == '%')
return (ft_putchar('%'));
else if (type == 'c')
return (ft_putchar(va_arg(li, int)));
else if (type == 's')
return (ft_check_s(li));
else if (type == 'd' || type == 'i')
return (ft_putnbr(va_arg(li, int)));
else if (type == 'p')
return (ft_check_p(li));
else if (type == 'x')
return (ft_puthexa(va_arg(li, unsigned int), "0123456789abcdef"));
else if (type == 'X')
return (ft_puthexa(va_arg(li, unsigned int), "0123456789ABCDEF"));
else
return (ft_putu(va_arg(li, unsigned int), "0123456789"));
}