RE: [Dev-C++] C validating user input
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <Mat...@Ve...> - 2005-03-16 00:26:36
|
make user enter number as string
then turn string into number with strtol function
strtol will check out the validity for you, but if something goes wrong it's
allowed to return certain error values. read the man page for it from Google
and be sure to catch whatever error conditions are listed and you should be
ok.
HTH!
Matt
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Dane
Ensign
Sent: Tuesday, March 15, 2005 3:34 PM
To: DEV C++ list
Subject: [Dev-C++] C validating user input
Hi all,
Using 'C' I need to prompt the user to enter an integer. Then I need to
check if it is between 0-18.
What is the safest approach?
I tried:
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.
Thank you in advance for any help you can offer.
Dane
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|