| | |
Reading data from a text file into an array
Our text file contains 10 words,and located in C:\ drive,we will read this data into an array and write out the results to the screen
Created by FlamingClaw 2009.04.26.
Created by FlamingClaw 2009.04.26.
Program Solution01; Var i:Byte; data:array[1..10]of String;{your array} F:Text;{file's variable} FileName:String;{stores the file's name and path} Lines:String; Counter:Integer; Procedure FileReadInToArray; Begin FileName:='C:\yourfile.txt'; Assign(F,FileName); {$I-} Reset(F); {open for reading} {$I+} If (IoResult = 0) Then Begin Counter:=1; While Not(EoF(F)) Do Begin ReadLn(F,Lines); Data[Counter]:=Lines; If (EoF(F)) Then Break; Inc(Counter);{increase 'Counter' by 1} End; {of while} End Else WriteLn('Error when reading the file'); Close(F); End; Begin {main} FileReadInToArray; {calling our procedure} For i:=1 To 10 Do WriteLn(i,'. element: ',Data[i]); ReadLn; End.{end of main} { the contents of yourfile.txt One word one line apple window pascal wine next day sun rain peach computer -=Created by FlamingClaw=- Written and tested in Dev Pascal 1.9.2. By me -=2009.04.26=- }
Similar Threads
- Writing and reading array to/from text file (C++)
- Reading from text file into array (C++)
- reading data from a text file (C++)
- Reading a text file Into an Array (C++)
- Help Reading Info in Text File Into an Array (C++)
| Thread Tools | Search this Thread |



