Also note
printf()
returns the number of characters output,
scanf()
returns the number of successful conversions. (it will save you 10-fold if you just spend an hour and read
man 3 scanf and understand in depth how the
format-string, the
optional-modifiers and each
conversion specifier behaves.
scanf()
is probably the No. 1 misused function by new C programmers (and probably responsible for 1:5 questions here) Understanding it fully is time well spent. Then you will know why user-input should be done with
fgets()
:)
—
David C. Rankin 6 secs ago