C 的一个问题 链表的,没把头结点定义成全局变量 出问题了,看看怎么改

#include <stdio.h>
#include <stdlib.h>

typedef struct node{
char data;
struct node *next;
}node;

node *CreatList();
void Print(node *head);

//node *p, *q;//*head;
//int n = 0;

void main()
{

node *head;
head = *CreatList();
Print(head);
}

node *CreatList()
{
node *head;
node *p;
int i;
head = (node *)malloc(sizeof(node));
p = head;
for (i = 1; i < 26; i++)
{
p->data = 'a'+ i - 1;
p->next = (node *)malloc(sizeof(node));
p = p->next;
}
p->data = i + 'a' - 1;
p->next = NULL;

return head;

}

void Print(node *head)
{
node *p;
p = head;
while(p)
{
printf("%c",p->data);
p = p->next;
}
}
提示
:error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct node' (or there is no acceptable conversion)

请教一下这个怎么改啊!谢谢

head = *CreatList();这句函数调用错了(应该是笔误吧),应该改为head = CreatList();改过后运行正常
希望能帮到你。。。
温馨提示:答案为网友推荐,仅供参考
相似回答