let's say an array like this:
1 2 3 4 5 6 7 6 5 4 3 1 7 2 5 3 1 4 2 6 8 9 7 6 4
How to count it from a file?
let's say an array like this:
1 2 3 4 5 6 7 6 5 4 3 1 7 2 5 3 1 4 2 6 8 9 7 6 4
How to count it from a file?
Why such tediousness in the comments? Such a task, as a rule, is automatically met in any educational / olympiad assignment)
It's simple:
var f: text; arr: array [0..4, 0..4] of integer; i, j: integer; begin AssignFile(f, 'c:\ 1.txt '); Reset(f); i := 0; while not Eof(f) do begin j := 0; while not Eoln(f) do begin Read(f, arr[i, j]); Inc(j); end; ReadLn(f); Inc(i); end; CloseFile(f); ... end.
If the size of the array is not known in advance, then it will be necessary to stretch the array as we go:
var f: text; arr: array of array of integer; i, j, w: integer; begin AssignFile(f, 'c:\ 1.txt '); Reset(f); i := -1; while not Eof(f) do begin Inc(i); SetLength(arr, i + 1); j:= -1; while not Eoln(f) do begin Inc(j); SetLength(arr[i], j + 1); Read(f, arr[i, j]); end; ReadLn(f); end; CloseFile(f); ... end.
Source: https://ru.stackoverflow.com/questions/152026/
All Articles