在 C 中打开文件

Opening a file in C

我在写这篇文章之前看了很多例子,我知道很多语言并且清楚地理解下面列出的代码中的语法和内容,但是,当我编译我的程序时:例如:

gcc -o /sbin/"name" readfile.c

我收到以下错误:

这对我来说毫无意义,因为我的代码清楚地包含 #include <stdio.h>,它定义了此处引用的 FILE ---- stdio.h

//程序 (readfile.c)

#include <stdio.h>

int main(){
    FILE *fp;
    fp = fopen("dummy.txt","w");
    fprintf(fp, "testing...\n");
    fclose(fp);
}

//FILE (dummy.txt) *在同一目录下

Hello World

只是一些小错误

 FILE *fp                     // semi-colon required
 fprint(fp, "testing...\n";   // Its fprintf and missing ')'
 flcose(fp);                 // fclose  is function 

函数是fprintf不是fprint也是fclose不是flcose

注意 - 您应该检查 fopen

中的 return