C fopen()错误:当从类型' struct FILE * '中分配' FILE '时,不兼容的类型。

时间:2023-01-13 16:12:35

I am currently in process of making an image-processing program and it is going pretty well but suddenly some fopen() errors appeared. In my previous version (no dynamically allocated arrays, no structs) it was okay, char name[50] was used in fopen(name, "a") and it worked good but now I cannot make it work at all. Whatever I throw in fopen(), it does not compile. Here is full error description:

我目前正在制作一个图像处理程序,它运行得很好,但是突然出现了一些fopen()错误。在我以前的版本中(没有动态分配的数组,没有struct),它是可以的,char[50]在fopen(名称,“a”)中使用,它工作得很好,但是现在我不能让它工作了。无论我在fopen()中抛出什么,它都不会编译。这里是完整的错误描述:

obsluga.c:30:8: error: incompatible types when assigning to type ‘FILE’ from type ‘struct FILE *’ plik2=fopen(name, "a");

obsluga。c:30:8:错误:不兼容的类型,当从类型' struct文件* ' plik2=fopen(名称,"a")中指定类型' FILE '时,不兼容的类型;

code fragment (I could post more but it should be irrelevant)

代码片段(我可以发布更多,但它应该是无关的)

char name[50]; 
plik2=fopen(name, "a");  

What I really want is to pass to fopen() file name contained in char *output which is in the appropriate structure but sadly even the easiest way doesn't work right now.

我真正想要的是将char *输出中包含的fopen()文件名传递到适当的结构中,但遗憾的是,即使是最简单的方法也不能立即生效。

1 个解决方案

#1


2  

To get the error, you must have written something like:

为了得到错误,你一定写了这样的东西:

FILE plik2;

instead of the correct:

而不是正确的:

FILE *plik2;

Treat FILE * as an opaque type. You always write FILE * (almost always; occasionally, you might use FILE **) and never write FILE.

将文件*视为不透明类型。你总是写文件*(几乎总是;偶尔,您可能会使用文件**),而从不写文件。

#1


2  

To get the error, you must have written something like:

为了得到错误,你一定写了这样的东西:

FILE plik2;

instead of the correct:

而不是正确的:

FILE *plik2;

Treat FILE * as an opaque type. You always write FILE * (almost always; occasionally, you might use FILE **) and never write FILE.

将文件*视为不透明类型。你总是写文件*(几乎总是;偶尔,您可能会使用文件**),而从不写文件。