-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
51 lines (46 loc) · 1.49 KB
/
ft_printf.c
File metadata and controls
51 lines (46 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aguiri <aguiri@student.42nice.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/02 15:11:54 by aguiri #+# #+# */
/* Updated: 2022/04/05 10:43:27 by aguiri ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_skip_spaces(const char *str, int *i)
{
int count;
count = 0;
if (str[*i] == ' ')
{
count = ft_printf_putchar_fd(' ', 1);
while (str[*i] == ' ')
(*i)++;
}
return (count);
}
int ft_printf(const char *arg_str, ...)
{
va_list arg_ptr;
int i;
int n_printed;
va_start(arg_ptr, arg_str);
i = 0;
n_printed = 0;
while (arg_str[i])
{
if (arg_str[i] == '%')
{
i++;
n_printed += ft_skip_spaces(arg_str, &i);
n_printed += ft_printf_arg(arg_str[i++], arg_ptr);
}
else
n_printed += ft_printf_putchar_fd(arg_str[i++], 1);
}
va_end(arg_ptr);
return (n_printed);
}