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 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() …
Jump to PostEven after you use fgets you will still have to use some if elses to check if the input violates the range restrictions
All 5 Replies
myk45 48 Posting Whiz
logicmonster 0 Light Poster
myk45 48 Posting Whiz
Salem 5,265 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.