423,350 Members | 2,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,350 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.
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,166
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.
2 Weeks Ago #2

Post your reply

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