Reading and recording in pascal



  • Hello. I'm here for the first time, so if you're not, you're right.

    How can a reading from a file be implemented if the data recording format is not known, i.e. it is not clear how it is written. For example, there's a file, there's a matrix in it.

    22 33

    44 55

    I don't know how to read it to keep the format of the recording, and I'll put it in a new file. If possible, with an example of such a program.

    Thank you for the answer.

    Complete.

    Well, I asked for opportunities... I can give you the code, but he won't give anything, I just don't know how to do it, so I asked.

    //считывание
    reset(f);
    for i := 1 to n do
    for j := 1 to n do
        read(f,x[i,j]);
    close(f);
    writeln ('матрица, считанная из файла');
    for i := 1 to n do
        begin
             for j := 1 to n do
                 write(x[i,j]:7:2);
             writeln;
        end;
    


  • If the record is like you said,

    reset(f);
    for i := 1 to n do
    begin
      for j := 1 to n do
        write(f, x[i,j]:7:2);
      writeln(f);
    end;
    close(f);
    

    The reading shall be:

    reset(f);
    for i := 1 to n do
    begin
      for j := 1 to n do
        read(f, x[i,j]);
      readln(f);  
    end;
    close(f);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2