Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!ucsd!orion.cf.uci.edu!uci-ics!bonnie.ics.uci.edu!asickels From: asickels@bonnie.ics.uci.edu (Alan Sickels) Newsgroups: comp.lang.pascal Subject: Re: Variable length output with Write(ln) inTurbo Pascal 5.0 Message-ID: <4171@paris.ics.uci.edu> Date: 14 Jan 89 20:37:23 GMT References: <1779@pur-phy> Sender: news@paris.ics.uci.edu Reply-To: Alan Sickels Organization: University of California, Irvine - Dept of ICS Lines: 30 In article <1779@pur-phy> murphy@newton.physics.purdue.edu (William J. Murphy) writes: >Does anyone know of a way using Write or Writeln to output a variable >length set of variables on a *single* line? Yes! Write does not put a carriage return when it is finished. The code looks something like this: for I := 1 to 10 do write(A[I]); writeln; which outputs the first 10 elements of array A. If you really want to get fancy, you can specify the width of the field the values will be printed in. write(A[I]:n); (* where "n" is an integer >= 0 *) will print the value in "n" spaces. If the value (including room for a + or -) is wider than "n", then the width will be adjusted to allow it to fit. If A is an array of reals, an additional value may be attached which specifies how many decimal places to want to print: write(A[I]:n:m); (* where n >= m + 2 and m >= 0 *) NOTE: The compiler will let you get away with "n >= 0", but it's good practice to leave a couple extra spaces for the decimal point and leading 0. Alan Sickels C:DOS - C:DOS:RUN - RUN:DOS:RUN - RUN:RUN:RUN