-
Notifications
You must be signed in to change notification settings - Fork 2
/
3-print_all.c
53 lines (51 loc) · 929 Bytes
/
3-print_all.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
#include <stdio.h>
#include <stdarg.h>
#include "variadic_functions.h"
/**
* print_all - prints anything.
* @format: a list of types of arguments passed to the function.
*
* Return: no return.
*/
void print_all(const char * const format, ...)
{
va_list valist;
unsigned int i = 0, j, c = 0;
char *str;
const char t_arg[] = "cifs";
va_start(valist, format);
while (format && format[i])
{
j = 0;
while (t_arg[j])
{
if (format[i] == t_arg[j] && c)
{
printf(", ");
break;
} j++;
}
switch (format[i])
{
case 'c':
printf("%c", va_arg(valist, int)), c = 1;
break;
case 'i':
printf("%d", va_arg(valist, int)), c = 1;
break;
case 'f':
printf("%f", va_arg(valist, double)), c = 1;
break;
case 's':
str = va_arg(valist, char *), c = 1;
if (!str)
{
printf("(nil)");
break;
}
printf("%s", str);
break;
} i++;
}
printf("\n"), va_end(valist);
}