#error in code using fstream

14 messages · Page 1 of 1 (latest)

severe rootBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

waxen yacht
#

did you check what is the meaning of fread return value?

severe rootBOT
#

fread, fwrite - binary stream input/output

Synopsis
#include <stdio.h>

size_t fread(void *restrict ptr, size_t size, size_t nmemb,
             FILE *restrict stream);
size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb,
             FILE *restrict stream);

hot kindle
#

what do you mean as in the fact it returns 0 if it cannot read into the file?

waxen yacht
#

it also returns 0 at the end of file

#

so you need to check what actually happened

#

fread() does not distinguish between end-of-file and error, and
callers must use feof(3) and ferror(3) to determine which
occurred.

hot kindle
#

asin whether it just reached the end of the file or if there was an error?

#

ah okay

#

sorry i am a beginner at all this im a bit confused how would i check for this?

waxen yacht
#

those are just another functions to call

severe rootBOT
#

feof — test end-of-file indicator on a stream

Synopsis
#include <stdio.h>

int feof(FILE *stream);

#

clearerr, feof, ferror - check and reset stream status

Synopsis
#include <stdio.h>

void clearerr(FILE *stream);
int feof(FILE *stream);
int ferror(FILE *stream);

ember burrow
#

"error in code using fstream" is pretty misleading as you don't even use std::fstream xD