fgets suddenly buggy behaviour (file stream damaged?)

J

jsmith

Hi,
what can cause a FILE* stream to no more read lines correctly
using fgets() ? It seems the line end delimiter (\n) doesn't
get evaluated correctly for _some_ lines.
The line numbers where that error happens changes with each run.
What can it be?
Environment is XP in Virtual Env (vbox), VC++ 2008.
 
J

Jack Applin

jsmith said:
what can cause a FILE* stream to no more read lines correctly
using fgets() ?

Bad code, usually. Produce a minimal example of code that compiles
and behaves incorrectly, and show it to us. Preparing the example
will often result in you figuring out what you did wrong.
 
J

Jorgen Grahn

Bad code, usually.

Specifically, fgets() is guaranteed to include the '\n' unless
- EOF has been reached
- the provided buffer is too short for the line of text

Also note that std::getline(istream&, string&) can be a better
alternative to C-style fgets() and FILE*.
Produce a minimal example of code that compiles
and behaves incorrectly, and show it to us. Preparing the example
will often result in you figuring out what you did wrong.

Yes.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top