能请帮我看看为什么连续输入学生信息后输出的姓名都是一样的?
#include <stdio.h>
#include <stdlib.h>
struct Student
{
char* name;
int num;
double height;
};
struct Node
{
struct Student data;
struct Node* next;
};
//创建一个链表(表头)
struct Node*createlist()
{
struct Node* headNode=(struct Node*)malloc(sizeof(struct Node));
headNode->next=NULL;
return headNode;
};
//创建一个结点
struct Node*createNode(struct Student data)
{
struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
newNode->data=data;
newNode->next=NULL;
return newNode;
};
//打印链表
void printList(struct Node*headNode)
{
struct Node*pmove=headNode->next;
while(pmove)
{
printf("%s\t%d\t%lf\n",pmove->data.name,pmove->data.num,pmove->data.height);
pmove=pmove->next;
}
printf("\n");
}
//头插法插入一个结点
void insertNodeByHeadNode(struct Node*headNode,struct Student data)
{
struct Node*newNode=createNode(data);
newNode->next=headNode->next;
headNode->next=newNode;
}
//寻找尾结点
struct Node*endofList(struct Node*list)
{
while(list->next) list = list->next;
return list;
}
//尾插法插入一个结点
void insertNodeByTrall(struct Node*list,struct Student data)
{
struct Node *lastNode = endofList(list);
struct Node *newNode = createNode(data);
lastNode->next = newNode;
}
int main()
{
struct Node*list=createlist();
struct Student info;
while(1)
{
printf("请输入学生的姓名、学号、身高:");
scanf("%s%d%lf",info.name,&info.num,&info.height);
setbuf(stdin,NULL);
insertNodeByTrall(list,info);
printf("继续输入(Y/N)?");
int choice2=getchar();
if(choice2=='n'||choice2=='N')break;
}
printList(list);
return 0;
}