This code:
#include <stdio.h>
void main()
{
char *csv_delimiter = ",";
printf("col1%scol2%scol3%scol4\n", csv_delimiter, csv_delimiter, csv_delimiter);
}
has this output:
col1,col2,col3,col4
That's exactly what I need. But I have to refer to the pointer csv_delimiter
multiple times. What if I had 1 thousand columns? Is there a way to refer to csv_delimiter
only once and print it multiple times to delimite as many columns as possible? I'm looking for some code like this:
#include <stdio.h>
void main()
{
char *csv_delimiter = ",";
printf("col1[REF1]col2[REF1]col3[REF1]col4\n", csv_delimiter);
}
As you can see from this example, I'm not looking for a loop (I can't loop in the original code due to reasons related to the implementation). I need some way to put a lot of %s
in a single line and refer them all to the same pointer, in this case csv_delimiter
. I'm sure this is possible. I remember reading something like this in Deitel, but I can't find where he explains how to do this.