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 | #include <stdio.h>
#include <stdlib.h>
#include <stdarg.h> // - This is required in any program that uses
// BUGGY
// variadic functions (additional arguments).
void print_many_strings(int num_strings, ...) { // - The ... stands for any number of arguments.
va_list more_args; // - Get a handle to the additional arguments.
va_start(more_args, num_strings); // - This is required to access them. Yes, it is weird.
for(int i = 0; i < num_strings; i++) { //
int next_num = va_arg(more_args, char*); // - Get the next additional argument.
printf("%d\n", next_num); // - Print it.
} //
va_end(more_args); // - This is required after you're done.
} // Yes, this is weird (too).
int main(int argc, char* argv[]) {
printf("print_many_strings(4, \"Choo\", \"choo\", \"choo\", \"whoo...\");\n");
print_many_strings(4, "Choo", "choo", "choo", "whoo..."); // <<<<<<<<<<<<<<<<
printf("\n");
printf("print_many_strings(4, \"Whoo\", \"whoo...\");\n");
print_many_strings(4, "Whoo", "whoo..."); // <<<<<<<<<<<<<<<<
return EXIT_SUCCESS;
}
|
© Copyright 2023 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.