Thread: please help

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    please help

    i would like to know how can i prevent user to key in characters in an int option by displaying error?

    i've used if else but it cant work...

    please help me as i'm new to c programming...

    thank u...

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Check the return value of scanf. Also, read the FAQ on getting a number from the user.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    thanks for answering but how to check the return value of scanf?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You just check and see what it is. Do you not understand about how functions return values?

    scanf


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    thanks for everything... i think i got it now... but mayb a quite stupid way...
    well as long as the program works that will do...

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well you could post your attempt, then we can tell you whether you're really on the right track.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed