I have a string like this.
char array1[250] = {"Array Values are %d,%d,%d,%d"};
And I have four integers like this,
int var1 = 25,var2 = 78, var3 = -189,var4 = -200;
I would like to print var1 to var4 in array1. How do I do that? I already have the format specifiers in array1 itself.
sprintf(array1, array1, var1, var2, var3, var4);Does it. However I’m not sure how kindly C will react to reading and writing to the same string at the same time, strongly advise you copy it into a separate variable first.
Edit: Per Roddy’s comment I’m just going to say don’t do what you are asking to do at all. Format specifier should be separated from data, I’m positive the application you’re using this in can spare 25 bytes for good design.