我正在尝试编写一个抽象数据类型来表示使用链接列表的整数项集。
我收到以下错误:
ERROR undeclared identifier 'linkedListSet'
error #2152: Unknown field 'code' of '(incomplete) struct LinkedListSet'.
并且觉得我必须用函数,结构和指针打破一些基本规则,但我真的无法弄明白。下面是我的代码,其中包含错误消息行。
#include<stdio.h>
#include<stdlib.h>
struct linkedListElement{
int data;
struct linkedListElement * next;
};
struct linkedListSet {
//struct linkedListElement * firstElement;
struct linkedListElement * header;
struct linkedListElement * current;
struct linkedListElement * temp;
int code;
};
struct linkedListSet * createdSet (){
struct linkedListSet * newSet = malloc(sizeof(linkedListSet));
//ERROR undeclared identifier 'linkedListSet'
newSet->header->data = 0;
newSet->header->next = NULL;
return newSet;
}
int addItem (struct LinkedListSet * setPtr, int info){
struct linkedListElement * newElementPtr;
setPtr->code = 3;
//error #2152: Unknown field 'code' of '(incomplete) struct LinkedListSet'.
return 1;
};
int main(){
return (0);
答案 0 :(得分:1)
尝试引用像这样的结构
typedef struct /* my struct tag */ {
int a;
int b;
} MyStructType;
以后
MyStructType * mystruct;
mystruct->a = 34;
// etc...
答案 1 :(得分:0)
linkedListSet
应为struct linkedListSet
:
struct linkedListSet * newSet = malloc(sizeof(struct linkedListSet));
LinkedListSet
应为linkedListSet
。
int addItem (struct linkedListSet * setPtr, int info)