C 取消引用指向未编译的不完整类型的指针

C 取消引用指向未编译的不完整类型的指针,c,C,因此,我正在编写一个程序,它使用双链接列表和节点遍历它们,同时执行简单的数学运算和添加/删除类型内容 我们一次又一次地检查代码和算法,试图找到逻辑问题,但我们看不到任何东西。当我们开始构建时,它显示了大约43个错误,主要是关于我使用临时节点遍历列表的位置的“取消引用”问题。我们有一个.c文件和一个.h文件 typedef结构在.h和#include中定义。我们只是不知道问题在哪里。我将代码链接在此粘贴箱中: 您遇到的最大问题是在DoubleLinkedListtypedef之前继续包含struc

因此,我正在编写一个程序,它使用双链接列表和节点遍历它们,同时执行简单的数学运算和添加/删除类型内容

我们一次又一次地检查代码和算法,试图找到逻辑问题,但我们看不到任何东西。当我们开始构建时,它显示了大约43个错误,主要是关于我使用临时节点遍历列表的位置的“取消引用”问题。我们有一个.c文件和一个.h文件

typedef结构在.h和#include中定义。我们只是不知道问题在哪里。我将代码链接在此粘贴箱中:


您遇到的最大问题是在
DoubleLinkedList
typedef之前继续包含
struct
,这会导致问题。
DNode
也会出现同样的问题。它渗透到代码中。您需要尽可能地阅读代码,您需要重新访问所有
calloc
调用。不清楚您试图做什么(是的,我知道您正在分配
DoubleLinkedList
DNode
,但您尝试的是不正确的

因此,我可以编译您的doublelinkedlist代码。除了提供一个diff(使用diff-uNrb创建)之外,没有其他简单的方法来显示更改。这将让您开始:

--- DoubleLinkedList.c
+++ DoubleLinkedList.c  2014-06-26 22:59:35.768919428 -0500
@@ -19,13 +19,13 @@
#include "DoubleLinkedList.h"


-typedef struct DNode mainTemp;
-typedef struct DoubleLinkedList mainList;
+DNode mainTemp;
+DoubleLinkedList mainList;

//1 DONE
-DoubleLinkedList* allocDList(uint elementSize){
+DoubleLinkedList* allocDList (uint elementSize) {

-   struct DoubleLinkedList* list = &mainList;
+        DoubleLinkedList* list = &mainList;

        list->head = NULL;
        list->tail = NULL;
@@ -35,18 +35,16 @@

        return list;

-
-
}
//2 DONE
void releaseDList(DoubleLinkedList* list){

-   struct DNode* node = list->head;
-   struct DNode* next = NULL;
+   DNode* node = list->head;
+   DNode* next = NULL;

        while(node){

-       struct DNode* next = node->next;
+       DNode* next = node->next;
                free(node);
                node = next;

@@ -56,12 +54,12 @@
//3 DONE
void insertDListElementAt(DoubleLinkedList* list, Object newElement, uint position){

-   struct DNode* newNode = calloc(list, sizeOf(newElement));
+   DNode* newNode = calloc (1, sizeof(newNode));  // allocating newNode or list?
        newNode->data = newElement;

        int counter = 0;

-   struct _DNode* current = list->head;
+   DNode* current = list->head;

        while(counter < list->length){

@@ -81,7 +79,7 @@
//4 DONE
void appendDList(DoubleLinkedList* list, Object newElement){

-   struct DNode* newNode = calloc(list, sizeOf(newElement));
+   DNode* newNode = calloc(1, sizeof(newNode));  // allocating newNode or list?
        newNode->data = newElement;

        newNode = list->tail->next; // setting newNode as current tail's next
@@ -95,7 +93,7 @@



-   struct DNode* newNode = (DNode*)calloc(list, sizeOf(newElement));
+   DNode* newNode = calloc(1, sizeof(newElement));

        newNode->data = newElement;

@@ -109,12 +107,12 @@
//6 DONE
DoubleLinkedList* reverseDList(DoubleLinkedList* list){

-   struct DoubleLinkedList* newList = NULL;
-   newList = (struct DoubleLinkedList*) malloc(sizeOf(DoubleLinkedList));
+   DoubleLinkedList* newList = NULL;
+   newList = malloc(sizeof(DoubleLinkedList));

-   struct DNode* temp = NULL;
+   DNode* temp = NULL;

-   temp = (DNode*)malloc(sizeOf(DNode));
+   temp = malloc (sizeof (DNode));

        temp = list->tail;

@@ -136,9 +134,9 @@
//7 DONE
DoubleLinkedList* halfList(DoubleLinkedList* list){

-   struct DNode* slow = list->head;
-   struct DNode* fast = list->head;
-   struct DoubleLinkedList* newList = malloc(uint);
+   DNode* slow = list->head;
+   DNode* fast = list->head;
+   DoubleLinkedList* newList = malloc (sizeof (uint));

        if(list->head != NULL){

@@ -166,7 +164,7 @@
Object removeDList(DoubleLinkedList* list, int position){

        int counter = 0;
-   struct _DNode* temp = list->head;
+   DNode* temp = list->head;

        while(counter < list->length){

@@ -189,11 +187,11 @@
//9 DONE
void printDList(DoubleLinkedList* list){

-   struct _DNode* temp = list->head;
+   DNode* temp = list->head;

        while(temp->next != NULL){

-       printf("%d", temp->data);
+       printf ("%d", temp->data);
                temp = temp->next;

        }
——DoubleLinkedList.c
+++DoubleLinkedList.c 2014-06-26 22:59:35.768919428-0500
@@ -19,13 +19,13 @@
#包括“DoubleLinkedList.h”
-类型定义结构DNode主温度;
-typedef结构DoubleLinkedList主列表;
+dnodemaintemp;
+双链接列表主列表;
//1完成
-DoubleLinkedList*allocDList(uint元素大小){
+DoubleLinkedList*allocDList(uint元素大小){
-结构DoubleLinkedList*列表=&mainList;
+DoubleLinkedList*列表=&mainList;
list->head=NULL;
list->tail=NULL;
@@ -35,18 +35,16 @@
退货清单;
-
-
}
//2完成
作废释放列表(DoubleLinkedList*列表){
-struct DNode*node=list->head;
-struct DNode*next=NULL;
+DNode*节点=列表->头部;
+DNode*next=NULL;
while(节点){
-struct DNode*next=node->next;
+DNode*next=节点->下一步;
自由(节点);
节点=下一个;
@@ -56,12 +54,12 @@
//3完成
void insertDListElementAt(DoubleLinkedList*列表,对象新元素,uint位置){
-struct DNode*newNode=calloc(list,sizeOf(newElement));
+DNode*newNode=calloc(1,sizeof(newNode));//分配新节点还是列表?
newNode->data=newElement;
int计数器=0;
-结构_DNode*当前=列表->标题;
+DNode*当前=列表->标题;
while(计数器<列表->长度){
@@ -81,7 +79,7 @@
//4完成
无效附件列表(DoubleLinkedList*列表,对象新元素){
-struct DNode*newNode=calloc(list,sizeOf(newElement));
+DNode*newNode=calloc(1,sizeof(newNode));//分配新节点还是列表?
newNode->data=newElement;
newNode=list->tail->next;//将newNode设置为当前tail的下一个
@@ -95,7 +93,7 @@
-struct DNode*newNode=(DNode*)calloc(list,sizeOf(newElement));
+DNode*newNode=calloc(1,sizeof(newElement));
newNode->data=newElement;
@@ -109,12 +107,12 @@
//6完成
DoubleLinkedList*反向列表(DoubleLinkedList*列表){
-struct DoubleLinkedList*newList=NULL;
-newList=(struct DoubleLinkedList*)malloc(sizeOf(DoubleLinkedList));
+DoubleLinkedList*newList=NULL;
+newList=malloc(sizeof(DoubleLinkedList));
-结构DNode*temp=NULL;
+DNode*temp=NULL;
-temp=(DNode*)malloc(sizeOf(DNode));
+temp=malloc(sizeof(DNode));
temp=列表->尾部;
@@ -136,9 +134,9 @@
//7完成
DoubleLinkedList*半列表(DoubleLinkedList*列表){
-struct DNode*slow=list->head;
-struct DNode*fast=list->head;
-结构DoubleLinkedList*newList=malloc(uint);
+DNode*slow=list->head;
+DNode*fast=列表->标题;
+DoubleLinkedList*newList=malloc(sizeof(uint));
如果(列表->标题!=空){
@@ -166,7 +164,7 @@
对象移除列表(DoubleLinkedList*列表,int位置){
int计数器=0;
-结构_DNode*temp=list->head;
+DNode*temp=list->head;
while(计数器<列表->长度){
@@ -189,11 +187,11 @@
//9完成
作废打印列表(DoubleLinkedList*列表){
-结构_DNode*temp=list->head;
+DNode*temp=list->head;
while(临时->下一步!=NULL){
-printf(“%d”,临时->数据);
+printf(“%d”,临时->数据);
温度=温度->下一步;
}

另外,除非您非常需要同时包含
DoubleLinkedList
DNode
(使用无效数据类型),一个简单的列表会更好地为您服务。您所做的是有效的,但这样做会使调试更加困难。有关简单的双链接列表示例,请参阅:。这是一个公平的示例。

请在问题中发布您的代码,而不是链接到外部站点。请努力删除任何不相关的代码,例如。发布您可以发布的最小代码,它仍然演示了问题。如果您可以包含相关定义,并向我们确切显示错误是什么,我们将更容易帮助您。通过发布代码的突出部分,您将避免被否决。我将去看一看,但在此处发布您的代码将使您免于Matt McNabb的痛苦建议。是的,很抱歉,我没有期待快速回复,所以我仍在编辑它。你能发布编译器错误吗?我怀疑在“typedef struct DoubleLinkedList mainList;”行中。如果你试图定义一个变量,请删除typedef。
typedef struct _DNode{

Object data;

struct _DNode* prev;

struct _DNode* next;

} DNode;
--- DoubleLinkedList.c
+++ DoubleLinkedList.c  2014-06-26 22:59:35.768919428 -0500
@@ -19,13 +19,13 @@
#include "DoubleLinkedList.h"


-typedef struct DNode mainTemp;
-typedef struct DoubleLinkedList mainList;
+DNode mainTemp;
+DoubleLinkedList mainList;

//1 DONE
-DoubleLinkedList* allocDList(uint elementSize){
+DoubleLinkedList* allocDList (uint elementSize) {

-   struct DoubleLinkedList* list = &mainList;
+        DoubleLinkedList* list = &mainList;

        list->head = NULL;
        list->tail = NULL;
@@ -35,18 +35,16 @@

        return list;

-
-
}
//2 DONE
void releaseDList(DoubleLinkedList* list){

-   struct DNode* node = list->head;
-   struct DNode* next = NULL;
+   DNode* node = list->head;
+   DNode* next = NULL;

        while(node){

-       struct DNode* next = node->next;
+       DNode* next = node->next;
                free(node);
                node = next;

@@ -56,12 +54,12 @@
//3 DONE
void insertDListElementAt(DoubleLinkedList* list, Object newElement, uint position){

-   struct DNode* newNode = calloc(list, sizeOf(newElement));
+   DNode* newNode = calloc (1, sizeof(newNode));  // allocating newNode or list?
        newNode->data = newElement;

        int counter = 0;

-   struct _DNode* current = list->head;
+   DNode* current = list->head;

        while(counter < list->length){

@@ -81,7 +79,7 @@
//4 DONE
void appendDList(DoubleLinkedList* list, Object newElement){

-   struct DNode* newNode = calloc(list, sizeOf(newElement));
+   DNode* newNode = calloc(1, sizeof(newNode));  // allocating newNode or list?
        newNode->data = newElement;

        newNode = list->tail->next; // setting newNode as current tail's next
@@ -95,7 +93,7 @@



-   struct DNode* newNode = (DNode*)calloc(list, sizeOf(newElement));
+   DNode* newNode = calloc(1, sizeof(newElement));

        newNode->data = newElement;

@@ -109,12 +107,12 @@
//6 DONE
DoubleLinkedList* reverseDList(DoubleLinkedList* list){

-   struct DoubleLinkedList* newList = NULL;
-   newList = (struct DoubleLinkedList*) malloc(sizeOf(DoubleLinkedList));
+   DoubleLinkedList* newList = NULL;
+   newList = malloc(sizeof(DoubleLinkedList));

-   struct DNode* temp = NULL;
+   DNode* temp = NULL;

-   temp = (DNode*)malloc(sizeOf(DNode));
+   temp = malloc (sizeof (DNode));

        temp = list->tail;

@@ -136,9 +134,9 @@
//7 DONE
DoubleLinkedList* halfList(DoubleLinkedList* list){

-   struct DNode* slow = list->head;
-   struct DNode* fast = list->head;
-   struct DoubleLinkedList* newList = malloc(uint);
+   DNode* slow = list->head;
+   DNode* fast = list->head;
+   DoubleLinkedList* newList = malloc (sizeof (uint));

        if(list->head != NULL){

@@ -166,7 +164,7 @@
Object removeDList(DoubleLinkedList* list, int position){

        int counter = 0;
-   struct _DNode* temp = list->head;
+   DNode* temp = list->head;

        while(counter < list->length){

@@ -189,11 +187,11 @@
//9 DONE
void printDList(DoubleLinkedList* list){

-   struct _DNode* temp = list->head;
+   DNode* temp = list->head;

        while(temp->next != NULL){

-       printf("%d", temp->data);
+       printf ("%d", temp->data);
                temp = temp->next;

        }