#include"stdio.h"
#include"string.h"
//#include"stdlib.h"
#include"malloc.h"
struct student
{
char name[20];
union
{
unsigned int dateint;
unsigned char date[4];
}date;
struct student *next;
};
int main(void)
{
struct student *head,*tail,*p,*pl;
char name1[20];
int date1;
head=tail=NULL;
printf("Please input the student'name and date:\n");
scanf("%s%x",&name1,&date1);
while(1){
p=(struct student *)malloc(sizeof(struct student));//开辟空间
strcpy(p->name,name1);
p->date.dateint=date1;
p->next=NULL;
if(head==0)
head=p;
else
tail->next=p;
tail=p;
printf("Please input the student's name and date:\n");
scanf("%s%d",&name1,&date1);
if(strcmp(name1,"end")==0)
break;
}
//输出函数
if(head==NULL)
printf("\n NO Records!!\n");
for(pl=head;pl;pl=pl->next)
//printf("姓名:%s 入学日期:%d%d/%d%d\n",pl->name,pl->date.date[3],p->date.date[2],p->date.date[1],p->date.date[0]);
printf("姓名:%s 入学日期:%d\n",pl->name,pl->date.dateint);
//free(p);
return 0;
}
分享到:
2011-10-21 18:42
浏览 580
评论