-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.c
More file actions
103 lines (94 loc) · 1.32 KB
/
helper.c
File metadata and controls
103 lines (94 loc) · 1.32 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "holberton.h"
/**
* _putchar - writes the character c to stdout
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _putchar(char c)
{
return (write(1, &c, 1));
}
/**
* op_c - character specifier and print
* @ap: argument pointer
*
* Return: count
*/
int op_c(va_list ap)
{
int count = 0;
_putchar(va_arg(ap, int));
count++;
return (count);
}
/**
* op_s - string specifier and print
* @ap: argument pointer
*
* Return: count
*/
int op_s(va_list ap)
{
int i = 0;
char *str;
int count = 0;
str = va_arg(ap, char*);
if (!str)
str = "(null)";
while (str[i] != '\0')
{
_putchar(str[i]);
count++;
i++;
}
return (count);
}
/**
* op_p - % specifier and print
* @ap: argument pointer
*
* Return: count
*/
int op_p(va_list ap)
{
int count = 0;
_putchar(va_arg(ap, int));
count++;
return (count);
}
/**
* op_d - digit specifier and print
* @ap: argument pointer
*
* Return: count
*/
int op_d(va_list ap)
{
int count = 0;
int mod = 1;
int d;
unsigned int di;
d = va_arg(ap, int);
if (d < 0)
{
_putchar('-');
di = d * -1;
count++;
}
else
di = d;
while (di / mod > 9)
{
mod = mod * 10;
}
while (mod > 0)
{
_putchar(di / mod + '0');
di = di % mod;
mod = mod / 10;
count++;
}
return (count);
}