Consider this scenario:
You ask the user for the original number. They enter this and then press enter:
The input buffer contains this:
So you read with scanf() and you get 123 as your number.
'1', '2', '3', 'a', 'b', 'c', '\n'
What will the next call to scanf() result in for a number? Hint: The buffer now contains this:
Basically, scanf() will ignore the non-numeric chars in this case, meaning the buffer is stuck this way. If you use scanf() you should be prepared for silly things like this. If you call getchar(), you end up with 'a'. Then you call again, and you end up with 'b'. One hackish solution to line up the input is to read from stdin until you hit either a '\n' or a newline char. For example:
'a', 'b', 'c', '\n'
This is answered in the FAQ btw, so you might get a better explanation from there.
while(((c = getchar()) != '\n') && (c != EOF));