-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
61 lines (54 loc) · 1.58 KB
/
ft_printf.c
File metadata and controls
61 lines (54 loc) · 1.58 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vpogorel <vpogorel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/28 16:40:29 by vpogorel #+# #+# */
/* Updated: 2024/12/05 17:13:13 by vpogorel ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static size_t ft_strlen(const char *str)
{
size_t len;
len = 0;
while (str[len])
len++;
return (len);
}
static int check_format(va_list args, const char *format)
{
int len_format;
int i;
int count;
count = 0;
i = 0;
len_format = ft_strlen(format);
while (i < len_format)
{
if (format[i] != '%')
{
count++;
write(1, &format[i], 1);
}
if (format[i] == '%' && i + 1 < len_format)
{
ft_check_flag(args, format[i + 1], &count);
i++;
}
if (i + 1 <= len_format)
i++;
}
return (count);
}
int ft_printf(const char *format, ...)
{
va_list args;
int count;
va_start(args, format);
count = check_format(args, format);
va_end(args);
return (count);
}