【问题标题】:C conflicting types for typedef struct [duplicate]typedef struct的C冲突类型[重复]
【发布时间】:2015-05-23 20:30:30
【问题描述】:

我的 C 程序有问题。我是新的 C 编程。我编写了一些代码,这里是我的错误和警告。

[Warning] conflicting types for 'setFirstValuesForSample' [enabled by default]

[Error] previous implicit declaration of 'setFirstValuesForSample' was here       

调用我的函数时我错过了什么?

#include <stdio.h>
    #include <stdlib.h>
    #define MAX_TERIM_SAY 101
    #define KARSILASTIR(x,y) (((x)<(y))?-1:((x)==(y))?0:1)
    typedef struct{
        int sat;//satır bilgisi
        int kol;//sütun bilgisi
        int deger;
    } terim;

    int main(int argc, char *argv[]) {
        terim a[MAX_TERIM_SAY],b[MAX_TERIM_SAY],c[MAX_TERIM_SAY];
        setFirstValuesForSample(a[MAX_TERIM_SAY],b[MAX_TERIM_SAY]);
        return 0;
    }
    void setFirstValuesForSample(terim a[],terim b[])
    {
        a[0].sat = 5;
        a[0].kol = 5;
        a[0].deger = 4;
    }

【问题讨论】:

    标签: c arrays function struct


    【解决方案1】:

    setFirstValuesForSample 在使用前未声明。因此它有一个隐式声明

    int setFirstValuesForSample();
    

    这与定义不符,

    void setFirstValuesForSample(terim a[],terim b[]) { ... }
    

    main中使用前需要提供正确的声明:

    void setFirstValuesForSample(terim a[], terim b[]);
    
    int main(int argc, char *argv[]) {
    
    /* as before */
    

    接下来,当你真正在 main 中调用它时,

    setFirstValuesForSample(a[MAX_TERIM_SAY],b[MAX_TERIM_SAY]);
    

    您正在传递两个terim 类型的参数。这也不符合定义。您需要将调用更改为

    setFirstValuesForSample(a, b);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      相关资源
      最近更新 更多