Thread: checking input int

  1. #1
    hurry up
    Guest

    checking input int

    whats the code or functionn that checks that the user has enter the integer as the input.if other than that ask the user again to enter the number again.
    Thanx! in hurry.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    FAQ
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Since im in a good mood ill give u a hint.
    ::hope i dont get punished by any mod by doing this::
    Ask the user for an integer ......then use scanf or whatever to read from stdin. Afterwards you check the value of the "integer" to see wether its a real integer by using......is_it_an_int()
    ....by using isdigit(int try_to_post_some_code_next_time) or isalpha().

    Make sure that u include ctype.h. Oh oh almost forget to make sure that the app asks for an integer again when the user didnt entered one you have to do all of this in a loop (wich one is up to you).

  4. #4
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    If your'e going to use scanf() to get the input, look here:
    Code:
    if(!scanf("%d",&myInt)) {
        //invalid input, the user didn't entered integer
    }
    
    else {
        //valid input make here, whatever you want
    }

  5. #5
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Well god diggity--damn made my day Vber .
    Thats a lots easier

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  2. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  4. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM