-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_printf.c
64 lines (59 loc) · 1.07 KB
/
_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
#include <stdio.h>
#include <stdarg.h>
#include "main.h"
/**
* _printf - Printf function
* @format: format.
* Return: count.
*/
int _printf(const char *format, ...)
{
va_list args;
va_start(args, format);
int count = 0;
for (int a = 0; format[a] != '\0'; a++)
{
if (format[a] == '%')
{
a++;
if (format[a] == 'd')
{
int value = va_arg(args, int);
count += printf("%d", value);
}
else if (format[a] == 'f')
{
double value = va_arg(args, double);
count += printf("%f", value);
}
else if (format[a] == 's')
{
char *value = va_arg(args, char *);
count += printf("%s", value);
}
else if (format[i] == 'c')
{
char value == va_arg(args, int);
count += putchar("%c", value);
{
else
{
count += putchar('%');
count += putchar(format[i]);
}
}
else
{
count += putchar(format[i]);
}
}
va_end(args);
return (count);
}
int main(void)
{
_printf("Hello, world!\n");
_printf("My name is %s, I am %d years old\n", "Raph-r7", 1);
_printf("The value of %s is %f\n", "PI", 3.14124);
return (0);
}