print format
Shiping Zhang
ping at cubmol.bio.columbia.edu
Tue Aug 7 10:29:24 AEST 1990
In article <31530014 at hpcvia.CV.HP.COM> brianh at hpcvia.CV.HP.COM (brian_helterline) writes:
>>
>> format = sizeof(largest_string);
>> for (i=0;array[i];i++)
>> printf("%[format]s\n",array[i]);
>> ^^^^^^^^
>> this is what I want to do.
>How about this:
>
> /* char string[10]; declare this somewhere */
>
> sprintf( string, "%%%ds\n", sizeof(largest_string));
^ ^ double quots would be missing from
string, should be modified a little bit
> /* string now looks like "%25s\n" or equiv. */
> for (i=0;array[i];i++)
> printf(string,array[i]);
The following should also work:
format = sizeof(largest_string);
for (i=0;array[i];i++)
printf("%*s\n",format,array[i]);
-ping
More information about the Comp.lang.c
mailing list