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

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.