Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!abvax!iccgcc!browns From: browns@astro.pc.ab.com (Stan Brown (216)371-0043) Newsgroups: comp.lang.c Subject: Re: print format Message-ID: <328.26b93bb8@astro.pc.ab.com> Date: 3 Aug 90 13:54:15 GMT References: <1990Aug2.162651.8083@uunet!unhd> Distribution: usa Lines: 20 In article <1990Aug2.162651.8083@uunet!unhd>, rgd@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 Sometimes even I don't stand behind my opinions; don't expect anyone else to!