函数的FILE参数 [英] FILE argument to a function
问题描述
我好像遇到了一个有趣的问题,
基本上我需要调用一个funcyon ReadGeometry和唯一的参数
我需要传递给它该函数是一个文件指针,所以我的功能
原型看起来像这样:
void ReadGeometry(FILE * ff1)
现在,我的编译器给出了编译时错误,指出FILE不能
启动参数声明
可能是最简单的方法修复这个只是传递一个常量的
char作为第一个参数,但这似乎是错误的传递给
函数一个我不需要的参数。 />
有什么想法吗?
这也只是我的copiler特定问题还是在C标准中
参数列表不能以FILE类型开头?
I seem to run into a funny problem,
basially i need to call a funcyon ReadGeometry and the only parameter
that i need to pass to that function is a file pointer, so my funtion
prototype looks like this:
void ReadGeometry(FILE *ff1)
Now, my compiler gives a compile time error stating that "FILE can not
start a parameter declaration"
Probably the easiest way to fix this would be to just pass a constant
char as the first argument, but that just seems wrong to pass to a
function a parameter that i dont need.
Any ideas?
Also is it just my copiler specific problem or is it in C standard that
argument list can not start with FILE type?
推荐答案
fermineutron写道:
fermineutron wrote:
我似乎遇到了一个有趣的问题,
基本上我需要调用一个funcyon ReadGeometry并且我需要传递给该函数的唯一参数
是一个文件指针,所以我的功能
原型看起来像这样:
void ReadGeometry(FILE * ff1)
现在,我的编译器给出了一个编译时错误,指出 FILE不能
启动参数声明
I seem to run into a funny problem,
basially i need to call a funcyon ReadGeometry and the only parameter
that i need to pass to that function is a file pointer, so my funtion
prototype looks like this:
void ReadGeometry(FILE *ff1)
Now, my compiler gives a compile time error stating that "FILE can not
start a parameter declaration"
你可能忘了#include< stdio.hbefore
宣布这个功能。
-
Eric Sosman
es ***** @ acm-dot -org.inva 盖
2006-11-08< 11 ****************** **** @ b28g2000cwb.googlegroups .com>,
fermineutron写道:
2006-11-08 <11**********************@b28g2000cwb.googlegroups .com>,
fermineutron wrote:
我好像遇到了一个有趣的问题,
基本上我需要调用一个funcyon ReadGeometry并且我需要传递给该函数的唯一参数
是一个文件指针,所以我的功能
原型看起来像这样:
void ReadGeometry(FILE * ff1)
现在,我的编译器给出了一个编译时错误说明FILE不能
启动参数声明
I seem to run into a funny problem,
basially i need to call a funcyon ReadGeometry and the only parameter
that i need to pass to that function is a file pointer, so my funtion
prototype looks like this:
void ReadGeometry(FILE *ff1)
Now, my compiler gives a compile time error stating that "FILE can not
start a parameter declaration"
您是否包含stdio.h?
Did you include stdio.h?
>
可能解决这个问题最简单的方法就是只传递一个常量的
char作为第一个参数,但这似乎是错误的传递给
函数一个参数,我不这样做需要。
>
Probably the easiest way to fix this would be to just pass a constant
char as the first argument, but that just seems wrong to pass to a
function a parameter that i dont need.
这没有用。 参数声明是
a单个参数的声明 - 即int x(int y,int z)包含两个参数
声明。
It wouldn''t help. a "parameter declaration" is the declaration of
a single argument - i.e. int x(int y, int z) contains two parameter
declarations.
有什么想法吗?
这也只是我的copiler特定问题还是用C标准来说
参数列表不能以FILE类型开头?
Any ideas?
Also is it just my copiler specific problem or is it in C standard that
argument list can not start with FILE type?
如果你包含了stdio.h,并且你得到了那个错误,那么你的编译器就错了。
If you included stdio.h, and you get that error, your compiler is wrong.
Eric Sosman写道:
Eric Sosman wrote:
您可能忘了#include< stdio.hbefore
声明该功能。
You probably forgot to #include <stdio.hbefore
declaring the function.
我确实包含了它。我在main.c中有一个main函数,我在ReadGeometry.c中有readGeometry
函数,我在NTC.h中有stdio和其他包含
文件。所有3个文件都是项目的一部分,NTC.h包含在
main.c中
ReadGeometry是NTC.h文件中的原型。
但是它会产生我上面描述的编译错误。如果我没有
包括stdio.ha总计不同的错误是geerated。
关于头文件的另一个问题,
我想以下是正确的,但我很感激有人
使它变得非常:
如果我有2个或更多的C文件,我有一个包含所有的头文件<全局和包含的
,我必须在每个C文件中分别#include" MyHeader.h"
。这是正确的吗?
I did include it. I have a main function in main.c, i have readGeometry
function in ReadGeometry.c and i have stdio and other includes in NTC.h
file. All 3 files are a part of a project and NTC.h is included in
main.c
ReadGeometry is prototyped in the NTC.h file.
But it generates the compile error i described above. If i do not
include stdio.h a totaly different error is geerated.
Another question about header files,
I think the following is correct, but i''d appreciate is someone
veryfied it:
if i have 2 or more C files and i have a header file which contains all
of the globals and includes, i have to separately #include "MyHeader.h"
into each of my C files. Is this correct?
这篇关于函数的FILE参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!