简单链接列表 – 无法访问节点

我正在尝试构建一个简单的链接列表但是我收到编译错误告诉我我正在尝试访问的链接列表节点不包含我期望它的字段。 这些是我的链接列表方法:

typedef struct TinCan { int label; } TinCan; typedef struct LinkedListNode { TinCan *data; struct LinkedListNode *next; } LinkedListNode; typedef struct LinkedList { LinkedListNode *head; } LinkedList; LinkedList* createList() /*creates empty linked list*/ { LinkedList* myList; myList = (LinkedList*)malloc(sizeof(LinkedList)); myList->head = NULL; } 

我malloc一个结构并将其发送到列表,如下所示:

 LinkedList* canQueue=createList(); TinCan* testCan = (TinCan*) malloc(sizeof(TinCan)); testProc->pid=69; insertLast(canQueue, testCan); void insertLast(LinkedList* list, ProcessActivity *newData) { int ii = 1; LinkedListNode* newNode = (LinkedListNode*)malloc(sizeof(LinkedListNode)); newNode->data = newData; //check if queue empty if(list->head == NULL) { list->head = newNode; newNode->next=NULL; } else { LinkedListNode* current = list->head; while (current->next != NULL) { current = current->next; } current->next = newNode; printf("%d", ii); ii++; } } 

然后我尝试像这样访问节点:

 testLinkedList(cpuQueue); void testLinkedList(LinkedList* list) { int count = 1; LinkedListNode* current = list->head; while (current != NULL) { printf("%d: Label is is %d", count, current->data->label); current = current->next; count++; } } 

编译错误显示最后一个方法:’LinkedListNode’没有名为’label’的成员。 我看不出哪里出错了,有人可以通过代码识别问题吗?

TinCan没有现场pid

也许:

 testProc->label=69; 

代替

 testProc->pid=69; 
 LinkedList* createList() /*creates empty linked list*/ { LinkedList* myList; myList = (LinkedList*)malloc(sizeof(LinkedList)); myList->head = NULL; 

– >返回myList;

 }