Aside from using switch statements, do-while loops, and if-else trees, is there a good way to complete error checking after a user input from the keyboard?
logicmonster
0
Light Poster
Recommended Answers
Jump to PostWhat do you mean by complete error checking after a user input from the keyboard ?
Could you give an example?
Jump to PostPerhaps something like this?
printf("Enter a number between 10 and 50: "); if ( scanf("%d", &myint) == 1 && myint >= 10 && myint <= 50 ) { // do stuff }
But if you wanted to really make it bomb-proof, you would need to use fgets() …
All 5 Replies
myk45
48
Posting Whiz
logicmonster
0
Light Poster
myk45
48
Posting Whiz
Salem
5,138
Posting Sage
abhimanipal
91
Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.