c - 在 C 中打开文件

标签 c linux fopen

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

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

我收到以下错误:

enter image description here

这对我来说没有意义,因为我的代码明确包含 #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/

相关文章:

c - 在 C 中使用 drand48_r 作为随机数生成器

c - 如何将结构体的预设数组放置在不同的结构体中?

python - 导入错误。没有名为 Commons 的模块错误 - python

c - 在C中的另一个目录中打开文件

php - 更快的 fopen 或 file_get_contents?

c - 如何使 g_idle_add/g_timeout_add 运行的函数异步工作?

c - 在自定义 shell 中处理参数

linux - 将多个域托管到同一服务器

linux - 检查目录是否存在不起作用

C程序在while循环中不保存到文件