The road to success will involve doing what the assignment asks you to do :) In particular, you should use one or more functions from conio.h
to read your input. scanf()
is not a conio.h function.
Because I'm lazy this is a homework question, I won't write the code for you.
One possibility would be to use cscanf()
rather than scanf()
. But this may (I don't know) echo input characters, which would include that accidental Enter, and not solve your problem.
If this is the case, my strategy would be to write a loop to gather characters entered from the keyboard, using the non-echoing getch()
function. You can ignore newlines until you have at least one printable character, and then accept characters (and store them in a character array or whatever) until you get a newline. Since input characters won't be echoed, I think the cursor will not move.
You can then scan the input characters from your input buffer using sscanf()
. You'll want to count input characters to make sure your user doesn't overflow your buffer. Also, probably some error handling in case of bad data.
EDIT: Something I forgot to mention: Your last input character in the buffer should be followed by a zero character ( '\0'
) so sscanf()
will terminate properly. It's possible for your buffer to be full of zeros by default, but putting one in there intentionally (e.g. when you hit your final newline) will make your code more correct and robust.