Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
EOF trouble Posted by robokop on 3 Jan 2005 at 10:51 AM
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

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.

Report
Re: EOF trouble Posted by _yilmaz on 4 Jan 2005 at 6:46 AM
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
:
:
: 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.
: 

:

Report
Re: EOF trouble Posted by robokop on 4 Jan 2005 at 8:11 AM
: 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
: :
: :
: : 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.
: : 

: :
:
:
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.
Report
Re: EOF trouble Posted by zibadian on 4 Jan 2005 at 9:19 AM
: : 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
: : :
: : :
: : : 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.
: : : 

: : :
: :
: :
: 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:
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;

This should read the entire file and display it on the screen.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.