C 功能原型问题
谢谢大家的建议!我不再在switch语句中使用该函数,但现在它给了我致命的错误。有人知道为什么现在无法编译吗?我是否仍在对其进行原型设计或定义错误?再次提前感谢C 功能原型问题,c,C,谢谢大家的建议!我不再在switch语句中使用该函数,但现在它给了我致命的错误。有人知道为什么现在无法编译吗?我是否仍在对其进行原型设计或定义错误?再次提前感谢 uhunix:/home04/y/yingkit/ee150% gcc functions2.c Undefined first referenced symbol in file largest_of_three
uhunix:/home04/y/yingkit/ee150% gcc functions2.c
Undefined first referenced
symbol in file
largest_of_three /var/tmp//ccEk23i2.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
这是全部代码:
#include <stdio.h>
#include <math.h>
//include macro functions if any
int main(void)
{
int repeat = 1;
int option = 0;
while(repeat == 1)
{
printf("\nOPTIONS:\n\n");
printf("1. Find the largest of three numbers.\n");
printf("2. Calculate the factorial of a number.\n");
printf("3. Truncate a number.\n");
printf("4. Round a number.\n");
printf("5. Find the inverse of a number.\n");
printf("0. Exit the program.\n\n");
printf("What do you want to do\?\n");
scanf("%i", &option);
float largest_of_three(float, float, float); //prototype
if(option == 0)
{
break;
}
if(option == 1)
{
float x = 0;
float y = 0;
float z = 0;
float result = 0;
printf("First number: ");
scanf("%f", &x);
printf("Second number: ");
scanf("%f", &y);
printf("Third number: ");
scanf("%f", &z);
result = largest_of_three(x, y, z); //calling
float largest_of_three(float x, float y, float z)
{
float w = 0;
if(x > y && x > z)
{
w = x;
}
else
{
if(y > x && y > z)
{
w = y;
}
else //middle
{
if(z > x && z > y)
{
w = z;
}
else
{
printf("There is no single greatest number.\n");
}
} //end middle else
} //end outer else
printf("The greatest number is %f.", w);
return w;
} //end largest_of_three function
} //end option 1
getchar( ); //to prevent buffer issues
printf("Would you like to do another operation\? Type y for yes, n for no.\n");
char yesno = 'y';
scanf("%c", &yesno);
if(yesno == 'y' || yesno == 'Y')
{
repeat = 1;
}
else
{
repeat = 0;
}
} //end while loop
return 0;
}
#包括
#包括
//包括宏函数(如果有)
内部主(空)
{
int repeat=1;
int选项=0;
while(重复==1)
{
printf(“\n选项:\n\n”);
printf(“1.查找三个数字中最大的一个。\n”);
printf(“2.计算数字的阶乘。\n”);
printf(“3.截断一个数字。\n”);
printf(“4.将数字四舍五入。\n”);
printf(“5.求一个数的倒数。\n”);
printf(“0.退出程序。\n\n”);
printf(“您想做什么\?\n”);
scanf(“%i”,选项(&O));
三个浮点数中最大的浮点数(浮点数、浮点数、浮点数);//原型
如果(选项==0)
{
打破
}
如果(选项==1)
{
浮动x=0;
浮动y=0;
浮点数z=0;
浮动结果=0;
printf(“第一个数字:”);
scanf(“%f”、&x);
printf(“第二个数字:”);
扫描频率(“%f”和“y”);
printf(“第三个数字:”);
scanf(“%f”、&z);
结果=三个(x,y,z)中的最大值;//调用
三个浮点数中最大的浮点数(浮点数x、浮点数y、浮点数z)
{
浮点数w=0;
如果(x>y&&x>z)
{
w=x;
}
其他的
{
如果(y>x&&y>z)
{
w=y;
}
else//middle
{
如果(z>x&&z>y)
{
w=z;
}
其他的
{
printf(“没有单个最大数。\n”);
}
}//中间结束
}//在其他地方结束
printf(“最大数量为%f.”,w);
返回w;
}//结束三个函数中最大的函数
}//结束选项1
getchar();//防止缓冲区问题
printf(“是否要执行其他操作\?键入y表示是,键入n表示否。\n”);
char yesno='y';
scanf(“%c”、&yesno);
如果(yesno=='y'| | yesno=='y')
{
重复=1;
}
其他的
{
重复=0;
}
}//在循环结束时结束
返回0;
}
第57行的代码是非法的。函数不能在ISO C中的其他函数中定义
该错误表明编译器有一个允许嵌套函数的扩展,使它们具有内部链接。但是你给出了一个带有外部链接的原型,不匹配
要解决此问题,请停止使用嵌套函数。(您可能可以通过在原型的开头添加
static
来修复它,但是这是一种糟糕的编码风格)。为什么您在那里有一个原型?这个函数是在哪里定义的?错误消息告诉您什么?最好将声明和定义移到开关
之外。如果您提供完整的文件,以便我们可以看到警告中的行号与代码中的行号相对应,这会有所帮助。“我在开关案例语句中放置了一个函数”-好吧,不要。这在C是不允许的。啊,好吧,我不知道。谢谢好的,谢谢!那我就把switch语句去掉。