#include "stdio.h"
#include<malloc.h>
#include<string.h>
#include<ctype.h>
#define LEN struct student
struct student{
char name[22];
int Chinese;
int Math;
int English;
struct student*next;
};
struct student*create()
{
char ch;
struct student *head;
struct student*p1,*p2;
int a=0;
printf("是否输入新数据:\n");
while(toupper(ch=getchar())=='Y')
{
p1=(LEN*)malloc(sizeof(LEN));
printf("name:");
scanf("%s",&(*p1).name);
printf("Chinese:");
scanf("%d",&(*p1).Chinese);
printf("Math:");
scanf("%d",&(*p1).Math);
printf("English:");
scanf("%d",&(*p1).English);
getchar();//getchar吸收回车
printf("是否输入新数据:\n");
a++;
if(a==1)
head=p1;
else
(*p2).next=p1;
p2=p1;
p1->next=NULL;
}
return(head);
}
void print(struct student *head)
{
struct student *p;
p=head;
while(p!=NULL)
{
printf("\nname:%-8sChinese:%-5dMath:%-5
dEnglish:%-5d",p->name,p->Chinese,p->Math,p->English);//只是一个名
p=p->next;//测试随便输
}
}
void main( ){
//struct student *stu;
//stu=create();
print(create());
}
Plan_C
习惯受伤
慕的地6079101
慕后端2529822
_dark
BanJim3313278
相关分类