-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
56 lines (51 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wollio <wollio@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/05 20:48:29 by wollio #+# #+# */
/* Updated: 2021/07/19 19:19:18 by wollio ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int print_char(char *string, int count, va_list arg)
{
int rt;
rt = 0;
while (*string)
{
while (*string && *string != '%')
{
ft_putchar_fd(*string, 1);
string++;
count++;
}
if (!*string)
break ;
string++;
rt = ft_specifier(&string, arg);
if (rt == -1)
return (0);
count += rt;
}
return (count);
}
int ft_printf(const char *format, ...)
{
va_list arg;
int count;
char *string;
char *string_2;
count = 0;
va_start(arg, format);
string = ft_strdup(format);
if (!string)
return (0);
string_2 = string;
count = print_char(string, count, arg);
free(string_2);
va_end(arg);
return (count);
}