Hello again,
I would like to ask how could I check if the input is right:
the program asks user to input a float from a keybord, but what if user inputs a char. Is there any funcion which can check that?
Thanks in advance.
Hi
You can use library function ischar() if you are using C to check if the input is a character or a quoted string. ischar returns TRUE if input was char , FALSE otherwise.
Manual method of doing it is this:
-
while(scanf("%f", &myFloatVal) == 0)
-
printf("Invalid input, enter again");
-
On success, the scanf() function returns the number of items succesfully read.
0 means no successful input (float in this example) is read.
Regards
Qi