2

如果一个值已经在里面,我想检查一个链接的元素列表,每个元素都包含一个整数。

struct ListenElement{
    int wert;
    struct ListenElement *nachfolger;
};

struct ListenAnfang{
    struct ListenElement *anfang;
};

struct ListenAnfang LA;

bool ckeckForInt(int value){
    if (LA.anfang == NULL){
        return 0;
    }
    return checkCurrent(LA.anfang, value);
}

bool checkCurrent(struct ListenElement* check, int value){
    if (check->wert == value){
        return true;
    }
    else if (check->nachfolger != NULL){
        return checkCurrent(check->nachfolger, value);
    }
    else{
        return false;
    }   
}

我得到了 checkCurrent 方法的冲突类型,但找不到它。

4

2 回答 2

4

checkCurrent()在声明或定义之前使用,这会导致生成返回类型为的隐式函数声明int(这与具有返回类型的函数的定义不同bool)。checkCurrent()在首次使用之前添加声明:

bool checkCurrent(struct ListenElement* check, int value);

bool ckeckForInt(int value){
    if (LA.anfang == NULL){
        return false; /* Changed '0' to 'false'. */
    }
    return checkCurrent(LA.anfang, value);
}

或将其定义移到checkForInt().

于 2013-04-30T13:01:39.137 回答
4

Is missing the function declaration. In C, you need to declare the function, exactly as it is.

struct ListenElement{
    int wert;
    struct ListenElement *nachfolger;
};

struct ListenAnfang{
    struct ListenElement *anfang;
};

struct ListenAnfang LA;

//The function declaration !
bool checkCurrent(struct ListenElement* check, int value);

bool ckeckForInt(int value){
    if (LA.anfang == NULL){
        return 0;
    }
    return checkCurrent(LA.anfang, value);
}

bool checkCurrent(struct ListenElement* check, int value){
    if (check->wert == value){
        return true;
    }
    else if (check->nachfolger != NULL){
        return checkCurrent(check->nachfolger, value);
    }
    else{
        return false;
    }   
}
于 2013-04-30T13:02:45.350 回答