我正在尝试编写一个抽象数据类型来表示使用链表的整数项目集。
我收到以下错误:
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);
尝试引用这样的结构
typedef struct /* my struct tag */ {
int a;
int b;
} MyStructType;
后来
MyStructType * mystruct;
mystruct->a = 34;
// etc...
>linkedListSet
应该struct linkedListSet
:
struct linkedListSet * newSet = malloc(sizeof(struct linkedListSet));
LinkedListSet
应该是linkedListSet
.
int addItem (struct linkedListSet * setPtr, int info)