making sure only integer is input



Hi All,

I have a number guessing game in which users try to guess a random number.
Obviously, input is required of type int.
BUT, when a user inputs a string the program will result in an undesired
infinite loop.
Now, I know a string is not what we're after but in terms of error-handling;
How can we prevent users from entering a string?
and if we can't do that:
How can we make sure if a string is entered, it is realized and discarded.
Implying, that the user is warned about the mistake and prompted again in
hope of correct input this time??

I have not included my program here because it is unncessarily large (still
a begginer), but if y'all want; more than happy to attach it.

Thanks for all your time in advance.


.



Relevant Pages

  • Re: making sure only integer is input
    ... I have a number guessing game in which users try to guess a random number. ... input is required of type int. ... I know a string is not what we're after but in terms of error-handling; How can we prevent users from entering a string? ... {/* declare a buffer for holding the input line */ ...
    (comp.lang.c)
  • Re: Extracting patterns after matching a regex
    ... Perhaps I need to find the string and then split it? ... I am just playing the guessing game like everybody else here. ...
    (comp.lang.python)
  • Re: help me plz
    ... SQL injection attack was the byval num as integer function argument. ... passing in the username as a string instead of the ID. ... > type int, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Efficent use of the string class
    ... //used later to hold each char in the string ... | 1) I compiled in release mode, so the compile could optimise the code. ... | release mode the compiler may optimise away the function call. ... | I thought your were implying that things got worse as the string got ...
    (comp.lang.cpp)
  • Re: read writte to file
    ... Note that cK is of type int and not char, ... to match the return type of getchar. ... A line is like a string, ... and a string is terminated by a '\0' character. ...
    (comp.lang.c)