-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_core_func.c
More file actions
56 lines (51 loc) · 1.77 KB
/
ft_printf_core_func.c
File metadata and controls
56 lines (51 loc) · 1.77 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_core_func.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tapulask <tapulask@21.school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/13 16:27:27 by tapulask #+# #+# */
/* Updated: 2022/03/13 16:27:37 by tapulask ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_num_handler(long int next_arg, const char **str_val, int *count)
{
if ((**str_val == 'd') || (**str_val == 'i'))
ft_putint(next_arg, &(*count));
(*str_val)++;
}
void ft_symb_handler(char *next_arg, const char **str_val, int *count)
{
if (**str_val == 'c')
ft_putchar(next_arg, &(*count));
else if (**str_val == 's')
ft_putstr(next_arg, &(*count));
(*str_val)++;
}
int ft_printf(const char *ptr, ...)
{
int count;
va_list ap;
if (ptr == NULL)
return (0);
va_start(ap, ptr);
count = 0;
while (*ptr)
{
if (*ptr == '%')
{
ptr++;
if ((*ptr == 'c') || (*ptr == 's'))
ft_symb_handler(va_arg(ap, char *), &ptr, &count);
else if ((*ptr == 'i') || (*ptr == 'd') || (*ptr == 'u'))
ft_num_handler(va_arg(ap, long int), &ptr, &count);
ft_print_percent(&ptr, &count);
}
else
ft_print_other_chrs(&ptr, &count);
}
va_end(ap);
return (count);
}