Mike Brown
Mike Brown

Reputation: 11

In C is there a way to print an array of unknown size with a single formatted print statement?

I have an array of strings and string representing the format for a printf statement. The number of strings in the array can vary, as can the format string (to match the number of strings in the array). Is there a way in C to print an array with a single format statement? I thought I'd be able to accomplish this with variadic functions, but there doesn't seem to be a way to pass an array as the args into va_list.

char mystring[3][20] = {"one", "two", "three"};
char format[] = "%-25s%-30s%s\n";

Upvotes: 0

Views: 215

Answers (1)

melpomene
melpomene

Reputation: 85767

No.͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏

Upvotes: 9

Related Questions