-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
47 lines (42 loc) · 1.56 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edesaint <edesaint@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/30 07:02:46 by edesaint #+# #+# */
/* Updated: 2022/11/30 08:51:09 by edesaint ### ########.fr */
/* */
/* ************************************************************************** */
// le prototype provient du man 3 printf
#include <stdarg.h>
int ft_printf(const char *format, ...);
int ft_printf(const char *format, ...)
{
va_list arg;
int len;
len = 0;
va_start(arg, format);
if (!format)
return (0);
if (!ft_strchr((char *) format, '%'))
{
ft_putstr_fd((char *) format, 1);
return (ft_strlen(format));
}
while (*format)
{
if (*format != '%')
len += write(1, *format, 1);
else
{
len += ft_convert_chosen(arg, *(format + 1));
format++;
}
format++;
}
va_end(arg);
return (len);
}
// retourne une valeur negative si une erreur apparait