Re: [Dev-C++] C validating user input
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel K. O. <dan...@ya...> - 2005-03-15 23:44:42
|
Dane Ensign wrote:
> What is the safest approach?
(...)
> int Num;
> printf("Enter a value between 0 and 18: ");
> scanf("%d", &Num);
>
> if(Num > 0 && Num <= 18)...
>
> but that makes the app go nuts if they enter: '.4' or something stupid
> like that.
Read the scanf() documentation to see what the returned value means.
It's enough for your simple input.
Daniel K. O.
|