print format
Stan Brown 216371-0043
browns at astro.pc.ab.com
Fri Aug 3 23:54:15 AEST 1990
In article <1990Aug2.162651.8083 at uunet!unhd>, rgd at uunet!unhd (Roger G Desroches II) writes:
> Is there a way to specify the format in a print statement with a variable.
> What I want to do is print out a group of strings so they are all right
> justified on the right side with the largest string. (example)
>
> format = sizeof(largest_string);
> for (i=0;array[i];i++)
> printf("%[format]s\n",array[i]);
> ^^^^^^^^
> this is what I want to do.
>
Do it this way:
format = strlen(largest_string);
for (i=0; arraay[i]; ++i)
printf("%*s\n", format, array[i]);
Stan Brown, Oak Road Systems
#include <disclaimer.h>
Sometimes even I don't stand behind my opinions; don't expect anyone else to!
More information about the Comp.lang.c
mailing list