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

Cha*_*nce 0 c ubuntu

我遇到了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 of type ‘struct FILE *’
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决这个问题.我试过稍微操纵指针,但它没有改变错误信息.这段代码是我希望代码执行的一个独立示例; 如果您想查看实际代码,请告诉我.这似乎是表达我所处理的更清晰的方式.

Dav*_*son 5

更改函数接受指针而不是结构本身:

void writeToFile(FILE * dataOut, char content[])
Run Code Online (Sandbox Code Playgroud)