Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!osu-cis!tut!lvc From: lvc@tut.UUCP Newsgroups: comp.lang.c Subject: Re: printf and variable length string format (asterisk) Message-ID: <2158@tut.cis.ohio-state.edu> Date: Mon, 23-Nov-87 17:50:50 EST Article-I.D.: tut.2158 Posted: Mon Nov 23 17:50:50 1987 Date-Received: Thu, 26-Nov-87 05:44:45 EST References: <692@zycad.UUCP> Organization: Ohio State Computer & Info Science Lines: 18 Summary: use .* In article <692@zycad.UUCP>, kjb@zycad.UUCP (Kevin Buchs) 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); > > ... * here is the minimum field length , use .* for the precision. See K&R pg 146-147. For your example you need: for (i=0; i<6; i++) printf("%.*s\n", i, a); Larry Cipriani AT&T Network Systems at cbosgd!osu-cis!tut!lvc Ohio State University