EOF trouble - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

EOF trouble

robokoprobokop Posts: 11Member
I have a code to read a file and write a file on the screen, but on some textfiles it stops to early with writing, and when I later in the progam progress the file it is not completely progressed is there a way to entirely progres the file

[code]
var fileloc : string;
textfile : text;
temp : char;

begin
readln(fileloc);
assign(textfile, fileloc);
reset(textfile);
while not eof(textfile) do
begin
read(textfile, temp);
write(temp)
end;
end.
[/code]

Comments

  • _yilmaz_yilmaz Posts: 150Member
    i dont know whether it is related to the problem or not, but
    you have to close the file after processing.

    : I have a code to read a file and write a file on the screen, but on some textfiles it stops to early with writing, and when I later in the progam progress the file it is not completely progressed is there a way to entirely progres the file
    :
    : [code]
    : var fileloc : string;
    : textfile : text;
    : temp : char;
    :
    : begin
    : readln(fileloc);
    : assign(textfile, fileloc);
    : reset(textfile);
    : while not eof(textfile) do
    : begin
    : read(textfile, temp);
    : write(temp)
    : end;
    : end.
    : [/code]
    :

  • robokoprobokop Posts: 11Member
    : i dont know whether it is related to the problem or not, but
    : you have to close the file after processing.
    :
    : : I have a code to read a file and write a file on the screen, but on some textfiles it stops to early with writing, and when I later in the progam progress the file it is not completely progressed is there a way to entirely progres the file
    : :
    : : [code]
    : : var fileloc : string;
    : : textfile : text;
    : : temp : char;
    : :
    : : begin
    : : readln(fileloc);
    : : assign(textfile, fileloc);
    : : reset(textfile);
    : : while not eof(textfile) do
    : : begin
    : : read(textfile, temp);
    : : write(temp)
    : : end;
    : : end.
    : : [/code]
    : :
    :
    :
    yes i know that i have done it already, this is just a part of the entire code, the problem is not fixed with that.
    the code is to encode and decode files, it only happens with coded files.
  • zibadianzibadian Posts: 6,349Member
    : : i dont know whether it is related to the problem or not, but
    : : you have to close the file after processing.
    : :
    : : : I have a code to read a file and write a file on the screen, but on some textfiles it stops to early with writing, and when I later in the progam progress the file it is not completely progressed is there a way to entirely progres the file
    : : :
    : : : [code]
    : : : var fileloc : string;
    : : : textfile : text;
    : : : temp : char;
    : : :
    : : : begin
    : : : readln(fileloc);
    : : : assign(textfile, fileloc);
    : : : reset(textfile);
    : : : while not eof(textfile) do
    : : : begin
    : : : read(textfile, temp);
    : : : write(temp)
    : : : end;
    : : : end.
    : : : [/code]
    : : :
    : :
    : :
    : yes i know that i have done it already, this is just a part of the entire code, the problem is not fixed with that.
    : the code is to encode and decode files, it only happens with coded files.
    :
    Then the coded files contain the end-of-file symbol before the actual eof. I would suggest an alternate method of loading using a file of char:
    [code]
    var
    f: file of char;
    ch: char;
    FileLength, i: integer;
    begin
    Assign(f, fileloc);
    Reset(f);
    FileLength := FileSize(f);
    for i := 0 to FileLength-1 do
    begin
    read(f, temp);
    write(temp)
    end;
    Close(f);
    end;
    [/code]
    This should read the entire file and display it on the screen.
Sign In or Register to comment.