A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 墓笙 中级黑马   /  2014-12-13 11:21  /  738 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

#include "stdio.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;
}
getch();
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马