请教前辈一个链表的问题
请教前辈,为什么在提示完“please input the record which you want to insert:”接收数据的时候当我刚输入完age的值的时候一敲回车就自动退出了,我还有一个数组mark[3]没赋值呢。
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
struct student
{
char name[30];
long number;
char gender;
int age;
float mark[3];
struct student *next;
};
int record = 0;
struct student *listinsert(struct student *head);
int main(void)
{
struct student *head;
head = initlist();
head = listinsert(head);
getch();
return 0;
}
struct student *initlist(void)
{
struct student *head;
head = NULL;
return head;
}
struct student *listinsert(struct student *head)
{
struct student *p1, *p2, *pi;
p1 = p2 = head;
printf("please input the record which you want to insert:\n");
pi = (struct student *)malloc(LEN);
scanf("%s %ld %c %d",&pi->name,&pi->number,&pi->gender,&pi->age);
printf("please input the score:\n");
scanf("%f %f %f",&pi->mark[0],&pi->mark[1],&pi->mark[2]);
if(p1 == NULL)
{
head = pi;
pi->next = NULL;
record++;
goto end;
}
if(pi->number <= head->number)
{
pi->next = head;
head = pi;
record++;
goto end;
}
while((pi->number > p1->number) && (p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(pi->number <= p1->number)
{
if(p1->next == NULL)
{
p1->next = pi;
pi->next = NULL;
record++;
}
else
{
p2->next = pi;
pi->next = p1;
record++;
}
}
else
{
p1->next = pi;
pi->next = NULL;
record++;
}
end:
printf("end!\n");
return head;
}