Reprinted from: http://blog.chinaunix.net/u3/99423/showart_2100968.html
I have made many mistakes in the scanf function, and I have also seen mistakes made by others. Remember to remind myself not to repeat the same mistakes. If it is useful to you,
Some features of scanf and scanfScanf is very sensitive. It is best not to set the accuracy and field width in scanf; otherwise, the input may fail.
Example:
# Include
Int main (void){Int a = 0;Scanf ("% 5d", & );Printf ("a = % d", );Return 0;}
I
Direct excerpt "C Primer Plus" calculation, too classic, I steal lazy, as a review ~I. OverviewInput from the keyboard is text, because those keys generate text characters: letters, numbers, and punctuation. For example, when you want to enter an
SCANF is very sensitive, it is best not to do scanf under the precision, field wide setting, otherwise the input may be invalid.Cases:#include int main (void){int a = 0;scanf ("%5d", &a);printf ("A =%d", a);return 0;}I run this code, when the input
The return value of printf () is the number of characters in the output String constant (note the difference between the number of characters and the number of words). Note that the count is for all printed characters, contains spaces and invisible
Small Embarrassment Between gets () and scanf (), getsscanf
It is a little embarrassing to get along with the scanf () function, that is, gets () is confused after scanf. Why? First, let's look at the similarities and differences between the two:
Preface
Before doing the curriculum design, inadvertently remembered to do the ACM topic commonly used line statement:
[CPP] view plain copy while (scanf ("%d", &a)! = EOF)
All of a sudden the effect of this sentence produced a curiosity, thought
"Summary"
This code is often encountered, while (scanf ("%d", &num)!=eof) {...}, the return value of EOF and the scanf function has not been well researched, this article will be a brief analysis of the problem.
Body"scanf function
The return value of the scanf is determined by the following arguments
scanf ("%d%d", &a, &b);
If both A and B are read successfully, then the return value of scanf is 2
If only A is read successfully, the return value is 1
If both A and B are not
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.