1. getc() function and end of file

Hello all,

I'm trying to process a file, an image of a disk, actually.  The file is 
about 1,450,000 bytes.

Anyway, my program always stops after only reading about 38,400 bytes.  It 
appears that getc(infile) is returning -1 (a ctrl-Z presumably), causing 
the program to quit.

The thing is, its nowhere near the end of the file yet.  How can I make 
getc(infile) keep going until it really reaches the end of the file?  Do I 
have to first look at the D_SIZE attribute from the dir() function, then 
use a for loop to read all of the data, or is there another way?

Thanks,
Ted Fines
Macalester College

new topic     » topic index » view message » categorize

2. Re: getc() function and end of file

Ted Fines wrote:

> I'm trying to process a file, an image of a disk, actually.  The file is
> about 1,450,000 bytes.
>
> Anyway, my program always stops after only reading about 38,400 bytes.  It
> appears that getc(infile) is returning -1 (a ctrl-Z presumably), causing
> the program to quit.

My guess is that the fle contains a #1A character. This is a Crtl-Z and for
files opened with mode "r", this will cause a premature End-Of-File (EOF) to
be returned.

Try opening the file with mode "rb" instead.

Another approach is to use get_bytes() instead of getc().

------
Derek Parnell
Melbourne, Australia
"To finish a job quickly, go slower."

new topic     » goto parent     » topic index » view message » categorize

3. Re: getc() function and end of file

Could you use something like this?

include get.e
include file.e

object junk
integer fn, file_length
sequence seq
seq = {}

 fn = open(" file_name " , "r")
 junk=seek(fn,-1)     
 file_length=where(fn)
 junk=seek(fn,0)

 seq = append(seq, get_bytes(fn, file_length))

Euman

----- Original Message ----- 
From: "Ted Fines" <fines at macalester.edu>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, April 06, 2001 16:40
Subject: getc() function and end of file


> 
> 
> Hello all,
> 
> I'm trying to process a file, an image of a disk, actually.  The file is 
> about 1,450,000 bytes.
> 
> Anyway, my program always stops after only reading about 38,400 bytes.  It 
> appears that getc(infile) is returning -1 (a ctrl-Z presumably), causing 
> the program to quit.
> 
> The thing is, its nowhere near the end of the file yet.  How can I make 
> getc(infile) keep going until it really reaches the end of the file?  Do I 
> have to first look at the D_SIZE attribute from the dir() function, then 
> use a for loop to read all of the data, or is there another way?
> 
> Thanks,
> Ted Fines
> Macalester College
> 
> 
> 
> 
> 
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: getc() function and end of file

Ted Fines wrote:

>Anyway, my program always stops after only reading about 38,400 bytes. It
>appears that getc(infile) is returning -1 (a ctrl-Z presumably), causing 
>the program to quit.

Did you open it in binary mode? If not, that could be your problem.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu