c - 如何修复此结构/链表脚本中的不兼容类型?

标签 c struct types linked-list

我正在编写一个脚本,以从 C 语言的文件中创建一个单词(本地)链接列表。基本上,我想要一个包含每行第一个单词的链接列表。 我收到错误“当从类型 't_local {aka struct local}' 分配给类型 'struct local *' 时类型不兼容”并且无法弄清楚发生了什么。非常感谢您的帮助,因为我在使用链表时遇到了一些困难

typedef struct local{
    char *name;
    struct local *next;

}t_local;


void crialistalocais(t_local *header){
    FILE *fp;
    t_local *aux = header->next;
    char line[150];
    char *name1;
    fp = fopen("loclss.txt","r");

    while (!feof(fp)){
        fgets(line, 100, fp);
        namel = strtok(line, '/');
        aux->name = namel;
        aux->next = *header;
        header=aux;
    }

}

最佳答案

aux->next = *header;

您正在取消引用 header 并尝试将 struct local 分配给 struct local*

关于c - 如何修复此结构/链表脚本中的不兼容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55891280/

相关文章:

go - 无需接口(interface)即可将多种类型合二为一

python - cython:减少类的大小,减少内存使用,提高速度

c - 为什么unsigned++不循环

C共享宏是一种在多个文件之间访问结构体成员的方法

typescript - 映射具有未知深度的通用 TypeScript 接口(interface)

快速检查对象类型

c - 从C到Shell : About "system" instruction

c - strcpy() 不起作用

c - 结构初始化问题?

c++ - 复制到数组时的 memcpy 与赋值;为什么这会生成不同的代码?