|
除了名字(NAME)可以正常读入,其他的都是随机值,而且SEX那边也有问题
struct stu_data//学生数据,分别记录学号,姓名,性别,年龄
{
long num;
char name[NAMELEN];
char sex;
int age;
struct stu_data *next;
};
struct stu_data *Crt(void)//创建链表
{
struct stu_data *head,*bk,*fwd;
head=fwd=bk=(struct stu_data*)malloc(LEN);
//head不存东西,从head->next开始存
fwd=head->next=(struct stu_data*)malloc(LEN);
printf("Now input the number,name,sex and age in order please\n");
printf("You can input 0 as a number to cease\n");
while(1) //如果输入学号为0就BREAK
{
printf("Num => ");
scanf("%ld",fwd->num);
if (fwd->num==0)
{
bk->next=NULL;
free(fwd);
break;
}
printf("Name => ");
scanf("%s",fwd->name);
printf("sex => ");
scanf("%c%c",fwd->sex);
printf("age => ");
scanf("%d",fwd->age);
bk=fwd;
fwd=fwd->next=(struct stu_data*)malloc(LEN);
}
return (head);
} |
|