I have very frequently seen people discouraging others from using scanf
and saying that there are better alternatives. However, all I end up seeing is either "don't use scanf
" or "here's a correct format string", and never any examples of the "better alternatives" mentioned.
For example, let's take this snippet of code:
scanf("%c", &c);
This reads the whitespace that was left in the input stream after the last conversion. The usual suggested solution to this is to use:
scanf(" %c", &c);
or to not use scanf
.
Since scanf
is bad, what are some ANSI C options for converting input formats that scanf
can usually handle (such as integers, floating-point numbers, and strings) without using scanf
?
No comments:
Post a Comment