Re: Having problem with my FRead in my program
- From: "Bruce Eitman \(eMVP\)" <beitmannospam@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Mar 2005 14:08:44 -0500
Those would not be my first choice of functions for reading the file, but
they should work.
CreateFile, WriteFile and ReadFile might give you more information for
debugging.
How do you open the file?
--
Bruce Eitman (eMVP)
Senior Engineer
beitman AT applieddata DOT net
Applied Data Systems
www.applieddata.net
An ISO 9001:2000 Registered Company
Microsoft WEP Gold-level Member
"Jean Nicolas Turcotte" <jn_turcotte_microstep@xxxxxxxx> wrote in message
news:e8HtE%23UNFHA.1172@xxxxxxxxxxxxxxxxxxxxxxx
> I am having problem reading some data in a file !
>
> I know this isn't the place to post and ask code like that but I have
> been searching for my problem for quite a time now and I don't know
> where else to post(if there is a better newgroup for this, please let me
> know). I am sure it's a little something that I just can't see.
>
> My file is a binary file. The first part of the file is a header with
> contains information about the file.
> Then everything under is another type of structure which contains logs
> of data.
>
> I have no problem writing and reading the first part (header), I don't
> think I have a problem writing the second part (the logs)
> But when I come to read the logs (second part) it doesn't work.
>
> The fread always return 0 and ferror doesn't return any error type.
>
> I need to specify that I am coding on a WCE platform 3.0 but that
> shouldn't make any difference here for reading and writing to a file.
>
>
>
>
> ****** Here is how I read my logs ******
> (logdata is a pointer to a structure of logs, and ScaleFile is a
> FilePointer to my already opened file)
>
>
> int CScaleFile::getNextLog(FLog *logdata)
> {
> int count = 0;
>
> fflush(ScaleFile);
> count = fread( logdata, sizeof(*logdata), 1, ScaleFile );
>
> if ( !ferror( ScaleFile ) ) {
>
> fflush(ScaleFile);
> return 0;
>
> } else {
> if ( feof(ScaleFile) != 0 )
> return -2; //An error other than EndOfFile occurred
> else
> return -1; //EOF occurred
> }
>
> }
>
>
>
>
>
> ****** This is how I write these logs ******
>
> bool CScaleFile::addLog(FLog *log)
> {
> if (GetIsOpen() ) { //If the file is open
>
> fflush(ScaleFile);
> fseek( ScaleFile, 0, SEEK_END);
>
> if ( fwrite( log, sizeof(*log), 1, ScaleFile) == 0 ) {
>
> return false;
>
> } else {
>
> fflush(ScaleFile);
> this->nbLog = this->getNbLog() + 1;
> return true;
>
> }
>
> } else
> return false;
>
> }
>
>
>
>
> ****** This is how I read my header *******
>
> bool CScaleFile::readHeader()
> {
> int count = 0;
>
> fseek( ScaleFile, 0, SEEK_SET );
> count = fread( &Header, sizeof(Header), 1, ScaleFile );
>
> if ( !ferror( ScaleFile ) ) {
>
> fflush(ScaleFile);
> return true;
>
> } else {
> return false;
> }
>
> }
>
>
>
>
> As you can see my ReadHeader and my ReadLogs are quite the same type of
> function, so I don't understand why it doesn't work here.
>
> If someone see what I am doing wrong, I would like to know cause I don't
> know anymore where to check for possible errors.
>
> Thank You !
.
- Follow-Ups:
- Re: Having problem with my FRead in my program
- From: Jean Nicolas Turcotte
- Re: Having problem with my FRead in my program
- References:
- Having problem with my FRead in my program
- From: Jean Nicolas Turcotte
- Having problem with my FRead in my program
- Prev by Date: Having problem with my FRead in my program
- Next by Date: Re: Having problem with my FRead in my program
- Previous by thread: Having problem with my FRead in my program
- Next by thread: Re: Having problem with my FRead in my program
- Index(es):
Relevant Pages
|