DPRG
DPRG List  



[DPRG] C programming question - reading binary files

Subject: [DPRG] C programming question - reading binary files
From: Clay Timmons ctimmons at cadence.com
Date: Thu Sep 16 18:20:45 CDT 2004

Working frantically on my robot...

I'm trying to get my robot's voice working again.  Dusting off old code
that worked years ago.

I'm having a problem reading a binary file.  Here is the code snippit.

fp = fopen(filename,"rb");   /* open for read of binary file */

while(!feof(fp)) {
	fscanf(fp,"%c",&val);
   ...
}


This works fine on every PC I've used except the new one onboard my
robot.
I'm reading a sound file, wave format.  I read the 8 bit samples and
dump them out the parallel port to a DAC (poor mans sound card).

The problem I'm seeing is that all values read back are zero. Also there
is a read failure at the end of file; ABORT, RETRY, IGNORE.

I suspect my problem may be caused by using a DiskOnChip for a hard
drive.
Not sure how well the Flash File System supports binary files.

My questions...

fopen - How is open binary different than a regular open?  "rb" vs "r"?

Reading from binary file - is fscanf the best way or should I use fgetc?
Both seem to give the same results.



Regards,

-Clay-



More information about the DPRG mailing list