-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3-print_all.c
More file actions
51 lines (49 loc) · 932 Bytes
/
3-print_all.c
File metadata and controls
51 lines (49 loc) · 932 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
#include <stdio.h>
#include <stdarg.h>
#include "variadic_functions.h"
/**
* print_all - Print anything through a variadic function
* @format: The list of types of arguments passed to the function
* Return: Nothing
*/
void print_all(const char * const format, ...)
{
int i = 0, exist = 0;
char *str_s = NULL;
va_list args;
while (format && format[i])
{
va_start(args, format);
i = 0;
while (format[i])
{
exist = 1;
switch (format[i])
{
case 'c':
printf("%c", va_arg(args, int));
break;
case 'i':
printf("%d", va_arg(args, int));
break;
case 'f':
printf("%f", va_arg(args, double));
break;
case 's':
str_s = va_arg(args, char *);
if (str_s == NULL)
str_s = "(nil)";
printf("%s", str_s);
break;
default:
exist = 0;
break;
}
i++;
if (format[i] && exist)
printf(", ");
}
va_end(args);
}
printf("\n");
}