Skip to content

Commit 8f94433

Browse files
committed
added: 2-print_strings.c
1 parent 8606271 commit 8f94433

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

0x10-variadic_functions/2-main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "variadic_functions.h"
2+
3+
/**
4+
* main - check the code
5+
*
6+
* Return: Always 0.
7+
*/
8+
int main(void)
9+
{
10+
print_strings(", ", 2, "Jay", "Django");
11+
return (0);
12+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "variadic_functions.h"
2+
#include <stdio.h>
3+
4+
/**
5+
* print_strings - prints a strings, followed by a new line.
6+
*
7+
* @sp: separator.
8+
* @n: num of args.
9+
*
10+
* Return: Nothing.
11+
*/
12+
void print_strings(const char *sp, const unsigned int n, ...)
13+
{
14+
unsigned int index;
15+
va_list ptr;
16+
char *string;
17+
18+
va_start(ptr, n);
19+
for (index = 0; index < n; index++)
20+
{
21+
string = va_arg(ptr, char *);
22+
if (string == NULL)
23+
printf("(nil)");
24+
else
25+
printf("%s", string);
26+
27+
if (index != n - 1 && sp != NULL)
28+
printf("%s", sp);
29+
}
30+
va_end(ptr);
31+
32+
printf("\n");
33+
}

0x10-variadic_functions/variadic_functions.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
int sum_them_all(const unsigned int, ...);
66
void print_numbers(const char *, const unsigned int, ...);
7+
void print_strings(const char *, const unsigned int, ...);
78

89
#endif /* VARIADIC_FUNCTIONS_H */

0 commit comments

Comments
 (0)