-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path2-print_strings.c
40 lines (39 loc) · 934 Bytes
/
2-print_strings.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
#include "variadic_functions.h"
/**
* print_strings - prints strings followed by a new line
*
* @separator: a pointer to the string to be printed between the strings
* @n: the number of strings passed to the function
*
* Return: void
*/
void print_strings(const char *separator, const unsigned int n, ...)
{
unsigned int runner;
va_list valist;
char *string;
va_start(valist, n);
/* I run trough the string to know which are the words ill print */
for (runner = 0; runner < n; runner++)
{
/* string is equal to the arguments in valist */
/* string now represents the arguments while va_Arg iterates */
string = va_arg(valist, char*);
/* task condition */
/* if one of the strings is NULL print (nil) */
if (string == NULL)
{
printf("(nil)");
}
else
{
printf("%s", string);
}
if (runner + 1 < n && separator != NULL)
{
printf("%s", separator);
}
}
printf("\n");
va_end(valist);
}