2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by draak13
0

>>fgets fails to work completely as advertised,
Nope -- it has been working correctly for millions of programmers all over the world during the past 25 years. If there was a bug in fgets() then it would have been found and corrected years ago. The problem is in your program, not in fgets().

>>fgets(mystring,9,fp); //I actually only want 8 characters, but fgets fails to work as it should, and only picks up 8

You declared mystring too small. If you want 8 characters in it then you have to declare the string to be at least 10 characters. fgets() may or may not append '\n' to the end of the string, depending on if '\n' is encountered in the file. It also appends the NULL string terminating character.

When dealing with character arrays its better to declare the array too big then too small. If you are going to err, then make it on the generious side.

0

>>fgets fails to work completely as advertised,
Nope -- it has been working correctly for millions of programmers all over the world during the past 25 years. If there was a bug in fgets() then it would have been found and corrected years ago. The problem is in your program, not in fgets().

Haha. I know =P. I was mostly annoyed with it earlier on today because I had to back up about 8 or 9 lines in order to get the ball rolling for everything else...and I couldn't figure why. But, I don't suspect that this issue has anything to do with my problem at all.

And, thanks for editing my post! I'll read up on the faq a little better before I do so next time.

-Ryan

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.