c语言 动态链表 完整代码 10分

来源:百度知道 编辑:UC知道 时间:2024/06/30 17:14:09
在线等 不行 运行不了VIsual studio 2005

#include "stdio.h"
#include "conio.h"

struct student
{
char name[12];
int score ;
char sex[6];
struct student * next;
};
main()
{
struct student * head ,* p1, * p2; struct student *p;
int n=0;
p1=p2=(struct student *)malloc(sizeof(struct student));
head=NULL;
printf("intput date name,score and sex:\n");
scanf("%s%d%s",&p1->name,&p1->score ,&p1->sex);
while (p1->score>=0)
{
n++;
if (n==1) head=p1;
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student));
printf("intput date name,score and sex:\n");
scanf("%s%d%s",&p1->name,&p1->score ,&p1->sex);
}
p2->next=NULL;
p=head;
while(p!=NULL)
{
printf("name:%s\nscore:%d\nsex:%s\n\n",p->name,p->score,p->sex);
p=p->next;
}