Validating input in c
The reason it is succeeding is because n is not altered by scanf() when the match fails, so the check is performed on an uninitialised 'n'. Url Encoded Form Entity; import org.client.methods. But the thing is it compiles but when i run it and i press a character such as the letter 'c' the program goes bolistic and goes into an inifinate loop how can i stop this with some validation to make sure that only an int is entered? Though you can more easily display your intentions by reversing the loop conditions: if the user input nothing before pressing ^D(unix like os) or ^Z(windows), and there is no such a test in function flush_stdin, then the program will stop and wait for the user to press ENTER.By calling feof to test stdin, we can avoid this unexpected thing It do need to call feof. The reason behind this is when you hit return\enter on your keyboard, a newline character is passed in as input.These extra hidden characters are what is messing with your input and spawning the infinite while loop.Hey guys how would i make sure that only an int is being entered and not a char.
So for the remainder of this post I'll pretend that your example will always behave as you think it does. That's an error condition that the calling code needs to handle.You can read a character string from the user with scanf, then convert it to an integer with strtol.For example, try the following program: Test it with 123, then with 123abc. Toast; public class Android PHPConnection Demo extends Activity These things you need top remember. Make sure the url you are providing to the android java code is correct. Also if connecting to a remote URL, you should have internet connection in your emulator or device. Make sure you have a database named mydatabase(in this case) and a table named “tbl_user” and some users inserted in it. Inside this folder I have a php file “check.php” which has the code for checking the user in the database.