User input being a number?

This is a discussion on User input being a number? within the C Programming forums, part of the General Programming Boards category; Hi guys, I have a technical question. How do I see if the user's input is a number? So for ...

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

    User input being a number?

    Hi guys,
    I have a technical question. How do I see if the user's input is a number?

    So for example, when they type in 6,4 how can I get both 6 and 4 to store it in two variables?
    I tried to implement this using a if statement like so : if(input == %d%d) but I guess it doesn't work like that.

    Help please?

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Read it in as a string, tokenize and parse it, and see if it matches the type of input you expected. If there is even a small deviation, discard the input and replace the user.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  3. #3
    THANK YOU KINDLY SIR Phenax's Avatar
    Join Date
    Mar 2011
    Posts
    74
    Quote Originally Posted by Watabou View Post
    Hi guys,
    I have a technical question. How do I see if the user's input is a number?

    So for example, when they type in 6,4 how can I get both 6 and 4 to store it in two variables?
    I tried to implement this using a if statement like so : if(input == %d%d) but I guess it doesn't work like that.

    Help please?
    ctype.h - Wikipedia, the free encyclopedia

    type.h is your friend.
    Also, scanf can scan multiple variables in a specified format. Google it up!
    Quote Originally Posted by Plato
    Never discourage anyone...who continually makes progress, no matter how slow.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to limit user input to a certain number of digits?
    By NewbGuy in forum C Programming
    Replies: 7
    Last Post: 05-08-2009, 10:57 PM
  2. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-30-2007, 12:16 AM
  3. Prevent user input
    By bonne_tim in forum C Programming
    Replies: 11
    Last Post: 01-01-2007, 03:18 PM
  4. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 06:20 AM

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