C language printf () and scanf () return value

1.printf()

In the printf C language () function can not only specify the information printed input to the screen, but this function there will be a return value in the process of implementation, the return value is the desired output number of characters in the string (including spaces and line breaks symbol)

#include <stdio.h>
int main(void){
    int c;
    int a=1111;
    c = printf("%dsgsgrg\n",a);
    printf("%d\n",c);
    return 0;
}

result:

1111sgsgrg
11

Including the \ n newline.

2.scanf()

scanf () in C language in general is to read input characters, which is the input function (in a real environment because the "stack overflow" or "buffer overflow" and so prone to security issues, it may not use more than ). Of course scanf () there is a return value, it returns the number of the variable value read from the input successful, if the type (numeric and character) are different, the read fails, the return 0.

#include <stdio.h>
int main(void){
    int c;
    int a;
    int b;
    int d;
    c = scanf("%d %d %d %d",&a,&b,&d);
    printf("%d\n",c);
    return 0;
}
54 56 56 44
4

Note: this code as an example, if a value is not entered in the input, but the character, the program does not read the characters and their contents later to enter the (back to read all failed).

56 fd 87 ee
1

Guess you like

Origin www.cnblogs.com/venoms/p/11520152.html