-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.c
80 lines (72 loc) · 1.14 KB
/
functions.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
71
72
73
74
75
76
77
78
79
80
#include "holberton.h"
#include <unistd.h>
/**
* _putstring - prints a string followed by a new line
* @str: string to print
*
* Return: number of chars printed
*/
int _putstring(char *str)
{
int i = 0, j;
while (str[i])
{
j = _putchar(str[i]);
if (j == -1)
return (j);
i++;
}
return (i);
}
/**
* _putchar - writes the character c to stdout
* @c: The character to print
*
* Return: number of chars printed
*/
int _putchar(char c)
{
int i;
i = write(1, &c, 1);
return (i);
}
/**
* checktype - matches a conversion specifier with its corresponding function
* @tp: char passed in by format
* @list: va_list from which to access
* Return: number of chars printed
*/
int checktype(char tp, va_list list)
{
id id[] = {
{"c", pc},
{"d", pd},
{"o", po},
{"i", pd},
{"b", pb},
{"s", ps},
{"u", pu},
{"x", px},
{"X", pxx},
{"p", pp}
};
int i, sum = 0;
for (i = 0; i < 10; i++)
{
if (id[i].type[0] == tp)
sum += id[i].f(list);
}
if (sum == 0)
{
if (tp != '%')
{
sum += _putchar('%');
sum += _putchar(tp);
}
else
sum += _putchar('%');
}
else if (sum == -2)
return (0);
return (sum);
}