学生信息管理 共用体与链表实现
2011-10-21 18:42
246 查看
#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;
}
#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;
}
相关文章推荐
- c语言使用链表编写一个可以实现班级学生管理系统,增加,删除,修改学生信息
- 使用单向链表实现学生信息管理系统
- C++链表类的三种使用方法(学生信息管理系统的实现)
- 链表实现:学生信息管理系统--SIMS
- 链表实现简单学生信息管理
- C语言实现学生信息管理系统(单链表)
- 用文件和链表实现学生信息管理
- 用链表实现学生信息管理(请教探讨!)
- 《数据结构》进行曲 之 单链表实现学生信息管理系统
- C语言使用链表实现学生信息管理系统
- 【C】用文件和链表实现学生信息管理
- 用单链表实现学生信息管理系统
- c++封装链表实现-->学生信息管理分析系统
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- java web学生信息管理系统的实现及源码(jsp servlet)
- 数据结构实验1 链表 实现学生信息存储,功能 增删改查,实现 结构类型
- <C语言>使用一个二维数组实现学生姓名管理系统,要求不能使用链表
- 使用结构体实现学生信息管理系统
- C语言实现学生信息管理系统
- 【C++】MFC 创建对话框,实现对课程信息和学生信息的管理