繁体   English   中英

C 编程 - 嵌套链表问题与打印

[英]C Programming - Nested Linked List issue with printing

我正在为课堂写作业,但遇到了一些问题。 与大多数编程课程一样,它们并不总是使用最佳实践来设置变量和代码,您必须让它发挥作用。

这是设置:

链接.h

//just showing the struct setup
typedef struct listCDT *listADT;

链接文件

//just showing the struct setup as all the other functions work
typedef struct point {
   listElementT x; 
   struct point *next;
} myDataT;

struct listCDT {
    myDataT *start;     // myDataT *header;
    myDataT *end;       // myDataT *footer;
};

驱动程序

//main is truncated to just the problem area
void main()
{
     listADT X, Y;
     X = NewList(); 
     Y = NewList();

     list_print_values(Y, "Y");
}

void list_print_values(listADT a, char *name)
{
        while (a != NULL)
        {
        printf("%d   ", *((*a)->start)->x););
        a = (&a)->end;
    }
    printf("\n");

    return;
}

driver.c 是我创建的唯一文件,我目前遇到的唯一问题是打印结构。 我收到以下错误:

>make
gcc  -c driver.c
driver.c: In function ‘list_print_values’:
driver.c:56:22: error: dereferencing pointer to incomplete type
   printf("%d   ", *((*a)->start)->x);
                      ^
driver.c:57:11: error: request for member ‘end’ in something not a structure or union
   a = (&a)->end;
           ^
make: *** [driver.o] Error 1

我已经尝试了几乎所有我能想到的东西,我一定错过了一些简单的东西吗? 任何人都可以帮忙吗?

结构成员可以使用. ->运算符。 一种用于结构指针,另一种用于结构。 在您的情况下,您正在访问结构指针的成员,因为您正在使用->您不需要取消引用。

printf("%d   ", (a->start)->x);
    a = a->end;

假设listElementtype int因此格式说明符%d

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM