How would I verify a users input? Like say the had to enter a number, and they entered a character, how would you check that?
How would I verify a users input? Like say the had to enter a number, and they entered a character, how would you check that?
You can check that manually by doing some Ascii arithmetic or use functions such as isalpha(), isdigit()....etc by including ctype.h
Prelude has written a validate function, do a board search to find it.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
> How would I verify a users input?
There are several, several ways.
> Like say the had to enter a number, and they entered a character, how would you check that?
One of the many ways, and easiest to catch on to:
Code:#include <stdio.h> #include <conio.h> int menu(void); int main(void) { char choice; while(menu() == 0) { choice=getch(); switch(choice) { case '1': printf("\n\nThe user entered the number 1"); printf("\n\nPress any key.."); getch(); break; case 'b': printf("\n\nThe user entered the letter b."); printf("\n\nPRess any key.."); getch(); break; case 27: printf("\n\nClosing.."); return 0; break; default: printf("\n\nThe user entered an invalid selection"); break; } } return 0; } int menu(void) { printf("\n\n1. Print message for character confirmation\n"); printf("B. Print message for character confirmation\n"); printf("Anything else - default message\n\n"); printf("Escape exits"); return 0; }
The world is waiting. I must leave you now.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
thanks everyone