C validating input char
It is not program's fault, after all, it is only doing what it is asked to do.If you as the programmer don't check for, or intercept garbage, it will accept anything.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.We'll use scanf here, but will make sure that the item entered is actually a single-digit integer.
The following code makes sure that the user enters a 3-digit number.
We need to add the statement to import it, before any other functions (main or otherwise).
We already used scanf (in the code above) to read user input.
I'm retired now, and one of the things I want to learn is python.
Although I can put a C or C program together with ease, I really struggle to get scripts to work. thanx, i m coding a lot of python latelly, making even gui apps with pygtk, and its great, simple, fast and very very easy to learn.