c - 我的 gcc 编译器给了我一个错误,显示为(函数)的类型冲突

标签 c compilation compiler-errors

我是 C 新手,我编写了这个程序,但遇到错误 “(函数)的冲突类型” “(函数)的先前声明在这里”。

我在我的系统上使用命令提示符使用 Dev c++ 的 gcc 编译器编译了这个。 谁能帮助我理解我的错误?

#include<stdio.h>
#include<math.h>
main()
{
    int a,b,c;
    float area;
    float ar(int a,int b,int c);
    printf("Enter the lenghts of the three sides of a triangle");
    scanf("%d%d%d",&a,&b,&c);
    area=ar(a,b,c);
    printf("The are a of the triangle is=%.2f",area);
}
ar(a,b,c)
{
    float area,s;
    s=(a+b+c)/3;
    area=sqrt((s*(s-a)*(s-b)*(s-c)));
    return area;
}

最佳答案

您声明了函数“ar”,其返回类型为 float 但 float ar(int a,int b,int c);但你定义它时没有返回值。这就产生了一个问题。 试试这个:

    #include<stdio.h>
    #include<math.h>
    float ar(int a,int b,int c);

    void main()
    {
        int a,b,c;
        float area;
        printf("Enter the lenghts of the three sides of a triangle");
        scanf("%d%d%d",&a,&b,&c);
        area=ar(a,b,c);
        printf("The are a of the triangle is=%.2f",area);
    }
    float ar(int a,int b,int c)
    {
        float area,s;
        s=(a+b+c)/3;
        area=sqrt((s*(s-a)*(s-b)*(s-c)));
       return area;
   }

使用命令编译:gcc -std=c99 -o stack_16_4_16 stack_16_4_16.c -lm

关于c - 我的 gcc 编译器给了我一个错误,显示为(函数)的类型冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36663061/

相关文章:

c - 从 C 中的偶数地址中删除字节

c - R .call() 接口(interface)和 EXTPTRSXP : Understanding PROTECT/UNPROTECT with externally allocated objects

C --- 全局变量的声明(重定义)问题

c - 预期的 ;之前)C 中的标记错误

compilation - 使用静态链接编译 wget,自编译(开放)ssl 库链接问题

performance - Scala 动态类管理

compiler-errors - 在 Xcode 7 Beta 2 上为架构 'com.apple.compilers.llvm.clang.1_0' 选择了不受支持的编译器 'x86_64'

java - 如何将值返回到二维数组?

haskell - 默认方法中对幻像类型的类约束的编译错误

c - C 中未定义行为的副作用是否已定义?