C错误(初学者)

3 c

#include <stdio.h>

main(void) {
file *file = fopen("words.txt","r") 
if(file != null) {
    char line[128];
    while(fgets( line, sizeof line, file) != null) 
    {
    fputs ( line, stdout );
    }
    fclose ( file );
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码.即时尝试读取文件,并输出内容.但这给了我错误代码

main.c: In function 'main':
main.c:4: error: 'file' undeclared (first use in this function)
main.c:4: error: (Each undeclared identifier is reported only once
main.c:4: error: for each function it appears in.)
main.c:5: error: parse error before "if"
main.c:7: error: 'line' undeclared (first use in this function)
main.c:7: error: 'null' undeclared (first use in this function)
main.c: At top level:
main.c:13: error: parse error before '}' token
main.c:13:2 warning: no newline at end of file
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误.

dic*_*ciu 9

错误地写入了FILE和NULL(C区分大小写).fopen line缺少分号.

下面的代码编译并运行.

#include <stdio.h>

main(void) {
FILE *file = fopen("words.txt","r"); 
if(file != NULL) {
    char line[128];
    while(fgets( line, sizeof line, file) != NULL) 
    {
    fputs ( line, stdout );
    }
    fclose ( file );
    }
}
Run Code Online (Sandbox Code Playgroud)


Sop*_*ert 2

尝试大写FILE