-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
67 lines (62 loc) · 1.73 KB
/
ft_printf.c
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_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jinpark <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 15:41:16 by jinpark #+# #+# */
/* Updated: 2019/06/17 13:38:51 by jinpark ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int count_lenth(char *str, int i)
{
int n;
int cnt;
cnt = 1;
n = i;
if (str[i] == '%')
i++;
if ((str[i] >= '0' && str[i] <= '9') || str[i] == '.' ||
str[i] == '-' || str[i] == '+' || str[i] == 'l' ||
str[i] == 'h' || str[i] == 'L' || str[i] == '#' ||
str[i] == ' ')
{
while ((str[i] >= '0' && str[i] <= '9') || str[i] == '.' ||
str[i] == '-' || str[i] == '+' || str[i] == 'l' ||
str[i] == 'h' || str[i] == 'L' || str[i] == '#' ||
str[i] == ' ')
{
cnt++;
i++;
}
}
return (cnt);
}
int ft_printf(char *str, ...)
{
va_list ap;
int cnt;
int res;
int i;
i = -1;
res = 0;
va_start(ap, str);
while (str[++i] != '\0')
{
if (str[i] == '%')
{
res += formatting(str, &ap, i);
cnt = count_lenth(str, i);
i += cnt;
}
else
{
ft_putchar(str[i]);
res++;
}
}
va_end(ap);
return (res);
}