我遇到了“类型冲突” C 中的错误
我目前正在为 C 课程编写一个程序,其中我必须输出形状的面积。
这是我在程序中使用的矩形区域函数:
double rectangle() // calculate area of rectangle
{
double length, width;
printf("\nEnter length and width of rectangle: ");
scanf("%g %g\n", &length, &width);
return (length*width);
}
这是我调用函数 rectangle()
的地方
if(strncmp(shape, "rectangle", 15) == 0)
area = rectangle();
。我在 Linux Mint 中使用 Geany 和 GCC 编译器。
我收到的错误是
“geometryv2.c:78:错误:‘矩形’的类型冲突”
我看不出这里有什么冲突。返回类型为 double 的函数返回 double。任何帮助将不胜感激。我对 C 还很陌生,这实际上是我的第一个 C 程序。
谢谢!
I'm currently working on a program for a C course in which I have to output the area of a shape.
Here is a function for a rectangle's area that I have in my program:
double rectangle() // calculate area of rectangle
{
double length, width;
printf("\nEnter length and width of rectangle: ");
scanf("%g %g\n", &length, &width);
return (length*width);
}
here is where I call the function rectangle()
if(strncmp(shape, "rectangle", 15) == 0)
area = rectangle();
I'm using Geany in Linux Mint with the GCC compiler.
The error I'm recieving is
"geometryv2.c:78: error: conflicting types for ‘rectangle’"
I don't see what's conflicting here. The function with return-type double is returning a double. Any help here would be greatly appreciated. I am still pretty new to C and this is actually my first C program.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在使用函数
rectangle()
之前声明了该函数?如果不是,则假定返回一个 int。您需要这样一行:
在调用它之前的某处,或者在调用它之前在调用它的同一模块中定义该函数。
Have you declared the function
rectangle()
before it is used? If not, it will be assumed to return an int.You need a line like:
somewhere before you call it, or to define the function in the same module from which it is called, before it is called.
区域变量的数据类型是什么?
还修复 scanf:
What is data type of area variable ?
also fix scanf: