当我用代码块编译这个程序时,我得到了未定义的“操作”引用。我只包含了显示错误的程序的一部分。我该如何解决这个错误?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
---------------------
---------------------
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n 2. YYY\n 3. ZZZ\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
case 2:
case 3:
case 4:operations();
return 0;
break;
default: printf("Wrong option choose again\n");
return 1;
}
}
void operations()
{
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n2. YYY\n3. ZZZ\n");
scanf("%d",&choice_of_options);
switch(choice_of_options)
{
---------
---------
}
}
}
}
答案 0 :(得分:1)
如果按照显示的消息进行操作,则需要在operations
中调用之前声明函数main
的原型。
void operations(void);
int main(void){
...
// then your code
答案 1 :(得分:1)
您不应在operations
函数中实施main
:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void operations()
{
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n2. YYY\n3. ZZZ\n");
scanf("%d",&choice_of_options);
switch(choice_of_options)
{
---------
---------
}
}
}
int main()
{
---------------------
---------------------
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n 2. YYY\n 3. ZZZ\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
case 2:
case 3:
case 4:operations();
return 0;
break;
default: printf("Wrong option choose again\n");
return 1;
}
}
}