Thread: input check

  1. #1
    Registered User
    Join Date
    Apr 2010

    input check

    how can i make sure that the user inputs the right amount of numbers.
    what i mean is:
    the input needs to be 2 int numbres with space between them. for example:
    4000 5000.
    and i want to make sure that if the user input only one number and press return,

    it will print "ERROR" and the program return 1.

    thank you for your help

  2. #2
    Registered User
    Join Date
    Jun 2005
    There are many ways. One way is reading the entire line of input to a string and then checking the content of that string to determine if it can be interpreted as two ints with an intervening space.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    if( scanf( "%d %d", &n1, &n2 ) == 2 )

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. allegro issues
    By mramazing in forum C++ Programming
    Replies: 1
    Last Post: 01-07-2009, 11:56 PM
  3. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  4. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM
  5. check if user input matches a word
    By fakebloo in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2004, 07:12 PM