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?

  • Specify the size known? What is a separator? - vdk company
  • I suppose his example is the content of the file - nolka
  • and what array? you can make an array of char, you can make an integer, even a String can turn out. Let him learn to ask questions if he has already started asking for help. - vdk company
  • This record set, while in a text file, is not an array as such. That you know that this is an array. Therefore, you have to read each line and process it as you need. Consequently, you create a dynamic two-dimensional array, and when reading each line, see if there is any data in it, and how many there are. If there is data, then increase the array vertically, depending on the number of objects, increase the array horizontally. - teanYCH
  • > That you know that this is an array. Oh, I also know) - Nofate

1 answer 1

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. 
  • and I was too lazy to write the code: * - teanYCH
  • useful to warm up in the morning - Nofate
  • one
    I didn’t recognize myself in the mirror in the morning ... what a warm-up was there ... I described the procedure, and it’s already good) - teanЫ