I can't think of a portable way to generate argument list, so i can't think of any simple solution better than typing the whole list like printf(template, 1, 2, 3, 4, 5, 6, ..., 49).
Another solution would be to manually go through the template and do something like:
#include <stdio.h>
#include <string.h>
void print_template_with_range(char *template, int start, int end) {
int i = 1;
char *str = strdup(template);
char *cur = str;
char *pos;
while ((pos = strstr(cur, "%2s")) != NULL) {
*pos = '\0';
printf("%s", cur);
printf("%2d", i++);
cur = pos + 3;
}
printf("%s", cur);
free(str);
}
int main() {
char* format_string = "\n\
%2s %2s %2s\n\
\n\
%2s R %2s\n\
\n\
%2s %2s %2s\n\
\n\
%2s %2s %2s %2s %2s %2s %2s %2s %2s %2s %2s %2s\n\
\n\
%2s B %2s %2s W %2s %2s G %2s %2s Y %2s\n\
\n\
%2s %2s %2s %2s %2s %2s %2s %2s %2s %2s %2s %2s\n\
\n\
%2s %2s %2s\n\
\n\
%2s O %2s\n\
\n\
%2s %2s %2s\n\
";
print_template_with_range(format_string, 1, 49);
return 0;
}
Produces:
1 2 3
4 R 5
6 7 8
9 10 11 12 13 14 15 16 17 18 19 20
21 B 22 23 W 24 25 G 26 27 Y 28
29 30 31 32 33 34 35 36 37 38 39 40
41 42 43
44 O 45
46 47 48