It was covered in the FAQ. Everyone else here grasps the concept, just not you.
Quzah.
It was covered in the FAQ. Everyone else here grasps the concept, just not you.
Quzah.
Hope is the first step on the road to disappointment.
quzah, I think you're wrong - it is not in the FAQ, because the reasoning in the FAQ doesnt apply as there is a check for the return value of fgetc(), although it was against '\n' instead of EOF.It was covered in the FAQ. Everyone else here grasps the concept, just not you.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Originally Posted by quzah
When was the last time you read the FAQ you quote so often? Please show me where it specifically address the problem with my code.
Free code: http://sol-biotech.com/code/.
It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up
The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw
The problem comes from idiots like you dragging on a discussion on how it's OK to use feof to control a loop, when such is not always the case. It's much easier to tell people to read the FAQ on the issue than it is to waste time with professionals like you in a debate of the times its "OK".
It's not OK. There are better ways to do it. It's much easier on all parties involved if you don't waste time doing it the way that "sometimes works" than it is to simply use a way that works all the time.
See, now I get to waste time with all of the other people that show up and say, "But I saw where it was OK!". Thanks.
I'll just add you to the list of morons who like to use fflush( stdin ) because it works "sometimes", and all of the other pointless debates on things that "sometimes" work. Hell, "sometimes" when I play with pointers that I haven't initialized, it "works" too.
Quzah.
Hope is the first step on the road to disappointment.
It is nice to know that you are a mature adult who is capable of carrying on a meaningful debate and not a childish twit who can only be rude and obstructive NOT.
Instead of a useful comment you simply say my code is wrong and the FAQ tells me why, yet when I ask you for clarification all you do is stamp you feet and continue saying it is wrong and the FAQ is the answer (something that continues to your most recent post). How is it that my code 'sometimes works'? How about an example of when it wouldn’t work? What better way would you suggest for counting linefeeds in a stream? Instead of doing something useful with your awesome wisdom and experience, all you do is whine like a petulant child who won't share his bat and ball. I have seen this sort of behavior in many of your posts; is this purely because you have so many posts and are full of yourself? If you have lost your desire to help people, why hang around? Do you just like to insult people? Despite that I mostly help people at these forums, I also learn as well, even with more than 10 years of professional programming experience; why can’t you take the time to be helpful instead of an ass?
Free code: http://sol-biotech.com/code/.
It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up
The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw
I was being helpful. I showed two people in the same thread EOF/feof issues they weren't aware of. You're just being intentionally ignorant now. Feof shouldn't be used to control loops. But since you're the professional, do as you like.
Had you really read the FAQ entry I mentioned, you would have seen a better way to do it. But since you're slow, I'll repeat it:
Now, this is better than your code for two reasons:Code:int c; while( (c = fgetc( fp )) != EOF ) if( c == '\n' ) newline++;
1) We're not using feof to control a loop. Why start a bad habbit when there's a better way? Oh, but wait, that's not good enough for you. You're miffed because I don't like your code. Too bad.
2) This version is twice as good as your code because this version only makes one function call per loop, while yours makes two. Twice as much work, just so you can use feof, which there is no point in using.
But hell, you're a professional, so you know all about writing super code. Guess not.
It's also apparent that you have some form of reading disability, because you don't seem to be able to read too well. I've explained why it's not a good idea to use it. The FAQ explains why it's not a good idea to use it. But like I said long ago, do whatever you like. No one here cares. Also, I really don't care if you write crappy code. But when you start saying it's a good way to do something, expect me to say otherwise.
Quzah.
Hope is the first step on the road to disappointment.
Dont worry. As you said, you´re not the only one who thinks that.Originally Posted by mitakeet
on the button as usual mitakeet
Ignoring the blaze all around, I'll take a stab at it.Originally Posted by mitakeet
Pretend I'm a noob and don't know any better. I've asked a programming forum about the best way to count all the new lines. Let's take your original code again:Sure, in this case, it works. The noob-me thinks it's awesome, but what happens when I later want to do a little more than just count newlines? Let's say I want to print every character. I might try something like this:Code:while (!feof(f)) { if (fgetc(f) == '\n') count++; }Looks reasonable to noob-me, but both you and I know that this is wrong.Code:while (!feof(f)) { putchar(fgetc(f)); }
In my opinion, that is what is incorrect with using feof to control a loop. It can work, but the programmer has to remember to that EOF is set on a read and program accordingly. It's easier to demonstrate checking for EOF on the read, since it always works.
[edit] I've got to agree with quzah...the information is all there in the FAQ.
Last edited by pianorain; 07-15-2005 at 07:00 AM.
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein