By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,218 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,218 IT Pros & Developers. It's quick & easy.

scanf how to return an invalid sign.

P: 1
I want to put a condition in c programing where if I ask a user for an input and they put a space between inputs I can give an error/invalid sign.
Sep 7 '18 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
This is very hard. You see, when the user inputs data your program is not running. It is paused by C until the user presses the ENTER key. You cannot control when the user presses this key.

After that your program resumes and you get to figure out what was entered.

All of the functions (like scanf, printf, etc) are provided just to get you started but they are not robust.

The work around is to examine each character as it is entered. Now then the user enters 1 then 2 then 3 you will need to process
these numbers to make an int of 123. But even now you cannot get the user to stop entering data.

As a beginner, just assume the user does the right thing. Later you can purchase code libraries that do all this hard stuff.
Sep 7 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.