Error check in C when a char has been entered intead of an int?
How can i check and creat a loop for the error in which a char has been entered by user insted of an int input!!!!??
Im new to C, so please keep it simple!!!!!!Tan x
I'd use a while loop, you can test the ASCII value, but it mostly depends on who you plan on reading it in.
I just suppose to get 3 int numbers as 3 sides of a triangle. So I cant allow the user to enter any char or decimals. So is the ASCII valuse a good choice in a while loop or not ( in error checking)?
I would recommend reading a value in as a char, then comparing that. You can use the char value, or convert it if you want. That, encompassed in a while, will probably do it.
i can do that. But there is a problrm.
what if a side of triangle be greater than 9. for example 123, 321, 32. Then what?
Hi ,
There are multiple way to solve ur problem.
1.check the return status of the scanf function and can conclude it.
2.get number as string and verify it then convert it to int.
3.get chars one by one then parese it and pass it to you program.
Regards,
Arul
Hi ,
There are multiple way to solve ur problem.
1.check the return status of the scanf function and can conclude it.
2.get number as string and verify it then convert it to int.
3.get chars one by one then parese it and pass it to you program.
Regards,
Arul
So i will get the int numbers in a string.....chec k to see if they are char or nor then convert them into int ...right????!!!
Comment