Thread: scanf undefined

  1. #1
    Unregistered
    Guest

    Question scanf undefined

    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

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    >> 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.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  4. #4
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    >> 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.

  5. #5
    Unregistered
    Guest
    Thanks to both of you. I have learned a lot of helpful things on this board

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM