| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
C++ Input Validation
I have written a very simplistic procedural program that asks the user for 3 input variables (working at the console level), and uses those inputs for calculations. Is there anything in C++ that allows me some sort of simple validation to make sure only numeric values are entered? In Java I have used IsNumeric() for this and have read about atoi() and such for C++ but can find no practical examples of its use. Checking for negative values was easy enough, but checking for alpha characters has me stumped! Any help or advice would be much appreciated.
|
|
#2
|
|||
|
|||
|
Well, I thought about this problem and came up with a solution. Now, I've been trying to integratge my idea into code but I can't get it to work. The idea is to to take each digit the user inputs and store it into an area using a for loop. Then, check each digit to see if it's numeric or alpha numeric. Simplest way to check this is take each digit and see if it's equivalent to a certain number 0 - 9. If you find that a digit is not equivalent to any number 0 - 9 then it must be alpha numeric. That's how I would approach this problem. It's just getting it into code. Hope that helped.
|
|
#3
|
|||
|
|||
|
The functions are you after are in the ctype.h standard library header.
Hope this helps, -KM- |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > C++ Input Validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|