Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!oddjob!gargoyle!ihnp4!homxb!mhuxt!mhuxm!mhuxo!ulysses!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c Subject: Re: printf and variable length string format (asterisk) Message-ID: <7478@alice.UUCP> Date: Mon, 23-Nov-87 21:27:18 EST Article-I.D.: alice.7478 Posted: Mon Nov 23 21:27:18 1987 Date-Received: Fri, 27-Nov-87 06:52:50 EST References: <692@zycad.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 20 In article <692@zycad.UUCP>, kjb@zycad.UUCP writes: > > I want to print out a string whose length I will not know ahead, and which > is not null terminated. I thought the following use of the asterisk > precision delimiter would work: > > char *a = "hello"; int i; > for (i=0; i<6; i++) printf("%*s\n", i, a); Almost. You want to say for (i=0; i<6; i++) printf("%*.s\n", i, a); When printing a string (or anything else), the number immediately after the % means the "field width" and represents the MINIMUM amount of space the field should occupy in the output. The number after the . means different things for different format types; for strings it represents the MAXIMUM number of characters transferred to the output.