please help

This is a discussion on please help within the C Programming forums, part of the General Programming Boards category; i would like to know how can i prevent user to key in characters in an int option by displaying ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,742
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21