-
Notifications
You must be signed in to change notification settings - Fork 0
/
_printf.c
70 lines (62 loc) · 1003 Bytes
/
_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "main.h"
/**
* _printf - Function that prints string
* @format: string to be printed
* Return: Length of string on success and -1 for error
*/
int _printf(const char *format, ...)
{
va_list input;
int i = 0, j = 0;
va_start(input, format);
if (!format || (format[0] == '%' && format[1] == '\0'))
return (-1);
for (i = 0; format[i] != '\0' && format != NULL; i++)
{
if (format[i] == '%')
{
if (format[i + 1] == '%')
{
_putchar('%');
i++;
j++;
}
else if (check(*(format + (i + 1))) == 1)
{
j += find_funct(*(format + (i + 1)), input);
i++;
}
else
{
_putchar(format[i]);
j++;
}
}
}
va_end(input);
return (j);
}
/**
* check - checks for type
* @s: to check
* Return: 1 on success
*/
int check(char s)
{
fin_t find[] = {
{'c', NULL},
{'s', NULL},
{'d', NULL},
{'i', NULL},
{0, NULL},
};
int i;
for (i = 0; find[i].ch != 0; i++)
{
if (find[i].ch == s)
{
return (1);
}
}
return (0);
}