| murdertrk (3) | ||||
|
Hi, I have coded a small code which only allows numbers (if i just wanted digits, i would use isdigit()) as inputs. I needed this because my program used to fail when i entered chars. That code should have made my job easier because it was supposed to ask for another entry when user enters a "non-integer" value. This is interesting that if i use this code in "main" function, it just works. But when i change it into a function (like "anti_char") it doesnt work. Code is here:
Although i enter a value between the interval i specified, it says "please enter an integer"
| ||||
|
|
||||
| ne555 (4383) | |||||
|
If that's C, it does not compile 16:2: error: a label can only be part of a statement and a declaration is not a statement. That's a bad use of goto, by the way.You've got several bad practices there, you should compile with warnings.
"%c" will just read 1 character (at most `9'), it will not put a null terminator in the string.And `&t' is not a pointer to a char. Because you don't have a null terminator, the string comparison will fail (the copy is dangerous and unnecessary). For error detection you could use strtol()
| |||||
|
|
|||||
| murdertrk (3) | |
|
I have tried almost everything to solve this problem but not looking at the scanf part of the pre-function. The whole problem was %c. I couldn't figure that out. Thanks dude ;) it should work by now. edit:and it didn't give any warnings. edit2:i would like to write something without goto but i felt so lazy :P | |
|
Last edited on
|
|