Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cunixf.cc.columbia.edu!cubmol!ping From: ping@cubmol.bio.columbia.edu (Shiping Zhang) Newsgroups: comp.lang.c Subject: Re: print format Message-ID: <1990Aug7.002924.3418@cubmol.bio.columbia.edu> Date: 7 Aug 90 00:29:24 GMT References: <1990Aug2.162651.8083@uunet!unhd> <31530014@hpcvia.CV.HP.COM> Reply-To: ping@cubmol.bio.columbia.edu (Shiping Zhang) Organization: Dept. of Biology, Columbia Univ., New York, NY Lines: 26 In article <31530014@hpcvia.CV.HP.COM> brianh@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