在写这篇文章之前,我看了很多例子,我知道很多语言,并且清楚地理解语法以及下面列出的代码中发生的情况,但是,当我编译我的程序时:
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
的返回
关于c - 在 C 中打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32526309/