I'm getting a "conflicting types" error in 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!
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:
double rectangle(void);
somewhere before you call it, or to define the function in the same module from which it is called, before it is called.
What is data type of area variable ?
also fix scanf:
scanf("%lg %lg")
精彩评论