小编Cha*_*nce的帖子

C"参数的类型为'struct file*'"

我遇到了C概念的问题.我会在前面,这是我的"编程专题:Linux和C"课程的一部分.我正在尝试创建函数将特定字符串写入文件(它是一个会计程序,函数写入页眉和页脚),我收到一个错误.

我的代码:

#include <stdio.h>

void writeToFile(FILE dataOut, char content[])
{
    fprintf(dataOut, content);
}

void main()
{
    FILE *dataOut;
    dataOut = fopen("testWrite.txt", "w");
    writeToFile(dataOut, "Leave no bars un-foo'd.");
}
Run Code Online (Sandbox Code Playgroud)

我尝试编译时收到的错误消息:

testWrite.c: In function ‘writeToFile’:
testWrite.c:5:2: error: incompatible type for argument 1 of ‘fprintf’
In file included from testWrite.c:1:0:
/usr/include/stdio.h:357:12: note: expected ‘struct FILE * __restrict__’ but 
argument is of type ‘FILE’
testWrite.c: In function ‘main’:
testWrite.c:12:2: error: incompatible type for argument 1 of ‘writeToFile’
testWrite.c:3:6: note: expected ‘FILE’ but argument is …
Run Code Online (Sandbox Code Playgroud)

c ubuntu

0
推荐指数
1
解决办法
4408
查看次数

标签 统计

c ×1

ubuntu ×1