I need to do one sprintf statement to format a char array, but it has one weirdness. Example:
int padding;
char format[n];
...
padding=10;
sprintf(format,"%%-%ds%.3f\n", padding, 3.141592654);
printf(format, "some text"
OUTPUT:
some text 3.142
Ok, here's the problem. What if I what to add the "some text" string into the format character array during the sprintf call, and not during the printf call? I have tried an arrangment of things, but can't see to find the one formatting string that does it all. Ideas?
Thanks,
-bitwise
I initially thought this would work:
sprintf(format,"%-%ds%.3f\n", padding, "some text", 3.141592654);
This does not work, and for obvious reasons. Any other ideas?
int padding;
char format[n];
...
padding=10;
sprintf(format,"%%-%ds%.3f\n", padding, 3.141592654);
printf(format, "some text"
OUTPUT:
some text 3.142
Ok, here's the problem. What if I what to add the "some text" string into the format character array during the sprintf call, and not during the printf call? I have tried an arrangment of things, but can't see to find the one formatting string that does it all. Ideas?
Thanks,
-bitwise
I initially thought this would work:
sprintf(format,"%-%ds%.3f\n", padding, "some text", 3.141592654);
This does not work, and for obvious reasons. Any other ideas?