The return values of scanf (), printf (), fscan (), and fprintf () are int type.
The return value of scanf () is the number of successfully entered data.
For example, scanf ("% d % s", & A, & B, S); 3 is returned if execution is successful.
Scanf ("% d", & A, & B); returns 2 if execution is successful.
If scanf ("% d", & A, & B) in the input process; for some reason, if A is successful, 1 is returned, if a and B fail, 0 is returned.
If an error occurs or an end of file is encountered, EOF is returned (generally, the macro defines EOF as-1 ).
Printf () returns the number of successfully output characters. Both int and escape characters are output by character.
For example, int A = 1, B = 2;
Char s [] = "hello ";
Int J;
J = printf ("% d % s", A, B, S );
Printf ("% d \ n", J );
Output: 12 hello
8
Why is it 8 instead of 7? The end escape character '\ 0' is at the end of string S'
If the preceding j = printf ("% d % s", a, B, s) is changed to j = printf ("% d % s",, b, s );
The output is: 1 2 hello // number of characters in the output sequence. Do not leave spaces empty.
10 // space is added between abs during output.
If it is changed to: int a = 10, B = 20;
Char s [] = "hello ";
Int j;
J = printf ("% d % s", a, B, s );
Printf ("% d \ n", j );
The output is: 1020 hello
10 // because the numbers 10 and 20 are two digits, each of them occupies two places in the output character sequence.
What is the result of printf failure? I really don't know. It seems that it has never failed.
Verify that the returned value of fscanf () is similar to that of scanf.
The returned value of fprintf () is similar to that of printf.