[英]Why is my function receiving an error that it is not defined in this scope? I am simply trying to call the function and have it run as of right now
I am simply trying to have the createList function called and run, but I get an error that create list was not defined in this scope. 我只是尝试调用并运行createList函数,但是我得到一个错误,即创建列表未在此范围内定义。 I am not sure what I am doing wrong.
我不确定我做错了什么。
typedef struct state {
char trans[100];
bool final;
struct state *next;
} STATE;
STATE *stu = NULL;
stu = createList(stu, trans, states);
STATE* createList (STATE *stu, char trans, int states) {
for (int i = states; i > 0; i--) {
printf("%d", i); /*ccode check*/
}
return stu;
}
If this is your C file, then there are two things to note: 如果这是您的C文件,那么有两点需要注意:
You must declare the function (ie a prototype) before you can use it. 您必须先声明该函数(即原型), 然后才能使用它。
You cannot have executable code on the global level. 您无法在全局级别拥有可执行代码。
Try: 尝试:
typedef struct state {
char trans[100];
bool final;
struct state *next;
} STATE;
STATE *stu = NULL;
STATE* createList (STATE *stu, char trans, int states) {
for (int i = states; i > 0; i--) {
printf("%d", i); /*ccode check*/
}
return stu;
}
int main (void)
{
stu = createList(stu, trans, states);
return 0;
}
Note that I didn't give a prototype in this example because the complete function is defined before it's used, so the compiler knows all about it. 请注意,我没有在这个例子中给出原型,因为在使用之前定义了完整的函数,因此编译器知道它的全部内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.