There are several posts on scanf being undefined behavior and some alternate things to do, but my question is why do they teach us to use it in school? Does anybody know why? The teaching makes no sense to me...
Thanks
There are several posts on scanf being undefined behavior and some alternate things to do, but my question is why do they teach us to use it in school? Does anybody know why? The teaching makes no sense to me...
Thanks
>> but my question is why do they teach us to use it in school? Does anybody know why?
same reason as they teach gets(), lazy teachers.
Last edited by C_Coder; 05-18-2002 at 03:29 PM.
All spelling mistakes, syntatical errors and stupid comments are intentional.
scanf is pretty well defined, it's just tricky to make it safe, and it has some unexpected effects when you try and mix scanf with say fgets.
I suppose while newbies are learning, anything to simplify expected input is perhaps a good thing, and allows them to focus on the problem at hand.
But at some point, there should be a lesson or two on dealing with input properly.
>> But at some point, there should be a lesson or two on dealing with input properly
Trouble is they don't. I was never told about scanf leaving newlines in the input buffer and when I did finally figure it out and ask about it I was advised to use fflush().
I can honestly say I've learnt tons more from this here board than I have in any classroom.
All spelling mistakes, syntatical errors and stupid comments are intentional.
Thanks to both of you. I have learned a lot of helpful things on this board