【求助】研究此程序5个小时还是没进展,希望大家帮忙
学校要求用链表编一个学生成绩管理系统,我在第一步成绩输入和输出就出问题了,输入成绩时在输入number那输入0不结束while循环,连续输入0倒是可以结束while循环,但是在输出时就成了死循环。求教高手如何解决。程序可能运行下会更好解决吧。谢谢大家帮忙,第一次发帖,请多指教。程序如下:
#include<stdio.h>
#include<malloc.h>
#include <string.h>
#define NULL 0
#define len sizeof(struct student)
struct student
{long num;
char name[20];
float msco;
float csco;
float esco;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(len);
printf("please input the number of the student:");
scanf("%ld",&p1->num);
printf("please input the name of the student:");
scanf("%s",&p1->name);
printf("please input the math of the student:");
scanf("%f",&p1->msco);
printf("please input the cprogram of the student:");
scanf("%f",&p1->csco);
printf("please input the english of the student:");
scanf("%f",&p1->esco);
head=NULL;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(len);
printf("please input the number of the student:");
scanf("%ld",&p1->num);
printf("please input the name of the student:");
scanf("%s",&p1->name);
printf("please input the math of the student:");
scanf("%f",&p1->csco);
printf("please input the cprogram of the student:");
scanf("%f",&p1->esco);
printf("please input the english of the student:");
scanf("%f",&p1->name);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
p=head;
if(head!=NULL)
do
{printf("%d",p->num);
printf("%s",p->name);
printf("%f",p->msco);
printf("%f",p->csco);
printf("%f",p->esco);
}while(p!=NULL);
}
main()
{
float arg,*point=&arg;
struct student *head;
head=creat();
print(head);
}