Warning: ignoring return value of 'scanf', declared with attribute warn_unused_result

#include 

int main() {
    int t;
    scanf("%d", &t);
    printf("%d", t);
    return 0;
}

提示:
prog.c: In function ‘main’:
prog.c:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result

就是提示你没有使用scanf的返回值

改进:

#include 

int main() {
    int t;
    if (scanf("%d", &t) == 1) {
        printf("%d", t);
    } else {
        printf("Failed to read integer.\n");
    }
    return 0;
}

转:https://stackoverflow.com/questions/7271939/warning-ignoring-return-value-of-scanf-declared-with-attribute-warn-unused-r

你可能感兴趣的:(C/C++,c,scanf)