-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0-printf.c
More file actions
56 lines (55 loc) · 893 Bytes
/
0-printf.c
File metadata and controls
56 lines (55 loc) · 893 Bytes
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
#include "main.h"
/**
* _printf - creating a custom printf
* @format: string format
* Return: 0
*/
int _printf(const char *format, ...)
{
va_list alx;
char c;
char *s;
int fd = 1;
int num = 0;
int d;
va_start(alx, format);
while (*format != '\0')
{
if (*format == '%')
{
format++;
if (*format == 'c')
{
c = va_arg(alx, int);
num += write(fd, &c, sizeof(char));
}
else if (*format == 's')
{
s = va_arg(alx, char *);
/* if (s == NULL)
{
write(fd, "(nil)", 5);
}*/
print_string(s, fd, &num);
}
else if (*format == 'd' || *format == 'i')
{
d = va_arg(alx, int);
handle_d_i(1, d);
num++;
}
else if (*format == '%')
{
c = va_arg(alx, int);
num += write(fd, "%", sizeof(char));
}
}
else
{
num += write(fd, format, sizeof(char));
}
format++;
}
va_end(alx);
return (num);
}