-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
64 lines (58 loc) · 2 KB
/
Copy pathft_printf.c
File metadata and controls
64 lines (58 loc) · 2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chanheki <chanheki@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/14 09:57:19 by chanheki #+# #+# */
/* Updated: 2022/10/14 15:12:51 by chanheki ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_check_format(const char *sentense, va_list ap)
{
int return_length;
return_length = 0;
if (*sentense == 'c')
return_length += ft_put_c((va_arg(ap, int)));
else if (*sentense == 's')
return_length += ft_put_s((va_arg(ap, char *)));
else if (*sentense == 'p')
return_length += ft_put_p((va_arg(ap, unsigned int *)));
else if (*sentense == 'd' || *sentense == 'i')
return_length += ft_put_n((va_arg(ap, int)));
else if (*sentense == 'u')
return_length += ft_put_u((va_arg(ap, unsigned int)));
else if (*sentense == 'x' || *sentense == 'X')
return_length += ft_put_x((va_arg(ap, unsigned int)), *sentense);
else if (*sentense == '%')
return_length += ft_put_c('%');
return (return_length);
}
int ft_printf(const char *sentense, ...)
{
va_list ap;
int return_length;
return_length = 0;
va_start(ap, sentense);
while (*sentense)
{
if (*sentense == '%')
{
sentense++;
return_length += ft_check_format(sentense, ap);
}
else
{
return_length += ft_put_c(*sentense);
}
sentense++;
}
va_end(ap);
return (return_length);
}
int ft_put_c(char c)
{
return (write(1, &c, 1));
}