Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!labrea!decwrl!hplabs!sdcrdcf!trwrb!scgvaxd!ashtate!dbase!csun!abcscnuk From: abcscnuk@csun.UUCP (Naoto Kimura) Newsgroups: comp.lang.pascal Subject: Re: Reading files Message-ID: <895@csun.UUCP> Date: Fri, 13-Nov-87 20:05:30 EST Article-I.D.: csun.895 Posted: Fri Nov 13 20:05:30 1987 Date-Received: Thu, 19-Nov-87 05:44:34 EST References: <5852@drutx.ATT.COM> Reply-To: abcscnuk@csun.UUCP (Naoto Kimura) Distribution: comp Organization: California State University, Northridge Lines: 73 In article <5852@drutx.ATT.COM> dsc@drutx.ATT.COM (DavisCS) writes: > >Help a beginner in Pascal?? > >Using Turbo Pascal on a PC - Is there a simple way (w/o parsing) to >read a file (on disk) where the values are a mixture of reals and >strings (on the same line). I DO know the layout, but only the maximum >length of the strings. For example the file might look like > >22.33 0.1234 12.19 >January 1.09 >22.54 99.22 Strawberries >999.0 1.2345 Blueberries >1.1 2.2 Apples > . > . > . >99.44 0.56 Ivory >0.0 0.0 LastAlpha > >I need to be able to pull out the reals and the strings for further >processing. > >Thanks in advance. Is the format of the file going to be just like the file above ? That is, sort of like this (# denotes real number, month, desc are strings) : # # # month # # # desc ... The first line and the last set of lines aren't any problem, since you can just use readln readln(num1,num2,num3); (* reads three numbers on first line *) readln(n1,n2,str); (* reads two numbers then a string *) to read them (Pascal takes care of things like that). The second line of the input could be a problem since you probably have a varying-length string is followed by a number. Lines like this one you'll have to parse. Just read the line into a string, then process it. All you have to do is to scan through the line, copying the characters into a string variable, until you hit a space (which I am assuming you are using as a delimiter). read(buf); i := 1; done := i > length(buf); while not done do begin s[i] := buf[i]; i := i + 1; if i > length(buf) then done := true else done := buf[i] = ' '; end; After extracting the string, you should have the number in the string after the space, which could be extracted by using a procedure or function (I don't recall the name, but it exists, just look in the manual) which converts a string into a number. //-n-\\ Naoto Kimura _____---=======---_____ (csun!abcscnuk) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!