47 lines
939 B
C
47 lines
939 B
C
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
|
|
void example(int number_of_args, ...);
|
|
|
|
int main()
|
|
{
|
|
char some_var[100] = "opt1";
|
|
char some_var2[100] = "opt2";
|
|
char some_var3[100] = "opt3";
|
|
|
|
char *psome_var = some_var;
|
|
char *psome_var2 = some_var2;
|
|
char *psome_var3 = some_var3;;
|
|
|
|
|
|
|
|
example(4, psome_var, psome_var2, psome_var3, psome_var);
|
|
// printf("Print array %s \n", some_var);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void example(int number_of_args, ...)
|
|
{
|
|
int i;
|
|
va_list curr_arg;
|
|
|
|
// the first option tells us the number of args... so therefore opt1=numberofargs.
|
|
va_start(curr_arg, number_of_args);
|
|
|
|
for(i = 0; i < number_of_args; i++)
|
|
{
|
|
printf("arg %d is: %s\n", i, va_arg(curr_arg, char*));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* printf("First arg: %s\n", va_arg(curr_arg, char*));
|
|
printf("second arg: %s\n", va_arg(curr_arg, char*));
|
|
printf("third arg: %s\n", va_arg(curr_arg, char*));
|
|
//printf("fourth arg: %s\n", va_arg(curr_arg, char*)); */
|
|
|
|
}
|