我正在编写一个脚本,以从 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/