#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
enum Sex{Male,Female};
typedef struct Student
{
char name[50];
char idnum[50];
enum Sex sex;
int age;
char adress[50];
char xibie[50];
char zhuanye[50];
int classnum;
struct Student *next;
}Link,*Pointer;
void Insert(Pointer * Head)
{
system("cls");
FILE *fp;
int n;
Pointer p,q,r;
char ch,temp[20];
bool flag = false;
if((fp=fopen("d:\\code\\001\\Input.dat","wb"))==NULL)
{
printf("Can not open the inform file!");
getch();
exit(1);
}
do
{
printf("\tPlease enter IDnum: ");gets(temp);
p = q = * Head;
while(p!=NULL)
{
if(!strcmp(p->idnum,temp)){
printf("\tThe student already input!\n");
flag = true;
break;
}else
{
q=p; //寻找下一个指针的节点
p=p->next; //走链
}
}
if(flag)
{
printf("\n\tDo you want input continue? -->(Y/N) [ ]\b\b");
ch=getchar();getchar();
if(ch=='N'||ch=='n')
break;
else
printf("\tPlease enter IDnum: ");gets(temp);
}
r=(Pointer)malloc(sizeof(Link));
r->next=NULL; //设置指针域
if(r==NULL)
{
printf("分配空间失败!\n");
return;
}
if(q==NULL)
*Head = r;
else
q->next = r; //在表尾插入元素
strcpy(r->idnum,temp);
printf("\tPlease enter name: ");gets(r->name);
printf("\tPlease select sex\n");
printf("\t[1]Male [2]Famale -->:[ ]\b\b");
gets(temp);n=atoi(temp);
if(n==1)
r->sex=Male;
else
r->sex=Female;
printf("\tPlease enter age: ");gets(temp);r->age=atoi(temp);
printf("\tPlease enter adress: ");gets(r->adress);
printf("\tPlease enter XIBIE: ");gets(r->xibie);
printf("\tPlese enter ZHUANYE: ");gets(r->zhuanye);
printf("\tPlese enter clasnum: ");gets(temp);r->classnum=atoi(temp);
fwrite(&r,sizeof(Link),1,fp);
printf("\tAny more?(Y/N):[ ]\b\b");
ch=getchar(); getchar();
printf("\n");
}while(ch=='y'||ch=='Y');
fclose(fp);
}
void Print()
{
printf("** * * * * * * * * * * **\n");
printf("* [1]Student Name *\n");
printf("* [2]Student IDnum *\n");
printf("* [3]Student Sex *\n");
printf("* [4]Student Age *\n");
printf("* [5]Studnet Adress *\n");
printf("* [6]Studnet ZhuanYe *\n");
printf("* [7]Student XiBie *\n");
printf("* [8]Studnet Classnum *\n");
printf("** * * * * * * * * * * **\n");
}
void Modify(Pointer Head)
{
system("cls");
Pointer p;
bool flag = true;
char f,c,ch[20];
int n;
do
{
printf("Please enter you want to modify student IDnum: ");
gets(ch);
p = Head;
while(p!=NULL&&flag)
{
if(!strcmp(p->idnum,ch))
{
Print();
printf("Please enter number you want to modify student message: [ ]\b\b");
f=getchar();getchar();
printf("\tPlease enter you data: ");
switch(f)
{
case '1':{gets(p->name);flag=false;break;}
case '2':{gets(p->idnum);flag=false;break;}
case '3':{printf("\tPlease select sex\n");
printf("\t[1]Male [2]Famale -->:[ ]\b\b");
c=getchar();getchar();
if(c=='1')
p->sex=Male;
else
p->sex=Female;
flag = false;
break;
}
case '4':{scanf("%d",&p->age);flag=false;break;}
case '5':{gets(p->adress);flag=false;break;}
case '6':{gets(p->zhuanye);flag=false;break;}
case '7':{gets(p->xibie);flag=false;break;}
case'8':{scanf("%d",&p->classnum);flag=false;break;}
}
}
else
p=p->next;
}
if(!flag)
printf("\tModify sucess!\n");
else
printf("\tCan not find this record!\n");
printf("\tModify any more?(Y/N):[ ]\b\b");
f=getchar();getchar();
}while(f=='Y'||f=='y');
}
void Delete(Pointer *Head)
{
system("cls");
char f;
char ch[20];
Pointer p,q;
bool flag = true;
do
{
printf("\tPlease input student num or student name you want to delete: ");
gets(ch);
q = p = *Head;
while(p!=NULL&&flag)
{
if(!strcmp(p->name,ch)||!strcmp(p->idnum,ch)){
if(p==*Head){ //删除表头元素
*Head = p->next;
free(p);
}else //删除普通元素
{
q->next = p->next;
free(p);
}
flag = false;
}else
{
q = p;
p = p->next;
}
}
if(!flag)
printf("\tDelete sucess!\n");
else
printf("\tCan not find this record!\n");
printf("\tDelete any more?(Y/N):[ ]\b\b");
f=getchar();getchar();
printf("\n");
}while(f=='Y'||f=='y');
}
void Search(Pointer Head)
{
bool flag = true;
char ch[20];
Pointer p;
char f;
do
{
system("cls");
printf("\n\tPlease input you want to search student IDnum or name : ");
gets(ch);
p=Head;
flag=true;
while(p!=NULL&&flag)
{
if(!strcmp(ch,p->idnum)||!strcmp(ch,p->name))
{
printf("\n\n\tYou want search student message\n\n");
printf("\tStudent Name: %s\n",p->name);
printf("\tStudent IDnum: %s\n",p->idnum);
if(p->sex==Male)
printf("\tStudent Sex: Male\n");
else
printf("\tStudent Sex: Female\n");
printf("\tStudent Age: %d\n",p->age);
printf("\tStudent Adress: %s\n",p->adress);
printf("\tStudent XiBie: %s\n",p->xibie);
printf("\tStudent Zhuan Ye: %s\n",p->zhuanye);
printf("\tStudent Classnum: %d\n",p->classnum);
printf("\n\n");
flag = false;
}
else
p=p->next;
}
if(!flag)
printf("\tSearch successd!\n");
else
printf("\tCan not find this message!!\n");
printf("\tSearch any more?(Y/N):[ ]\b\b");
f=getchar();getchar();
}while(f=='y'||f=='Y');
}
void Show(Pointer Head)
{
system("cls");
Pointer p;
p = Head;
bool flag=false;
int tot = 1;
while(p!=NULL)
{
printf("\n\tThe %dth student\n\n",tot);
printf("\tStudent Name: %s\n",p->name);
printf("\tStudent IDnum: %s\n",p->idnum);
if(p->sex==Male)
printf("\tStudent Sex: Male\n");
else
printf("\tStudent Sex: Female\n");
printf("\tStudent Age: %d\n",p->age);
printf("\tStudent Adress: %s\n",p->adress);
printf("\tStudent XiBie: %s\n",p->xibie);
printf("\tStudent Zhuan Ye: %s\n",p->zhuanye);
printf("\tStudent Classnum: %d\n",p->classnum);
p = p->next;
printf("\n");
tot++;
flag = true;
}
if(flag)
printf("\n\tSuccess to show students message.\n\n");
else
printf("\n\tHave not student message!\n");
}
char Menu()
{
char num;
printf(" ** * * * * * * * * * * * * * * * *\n");
printf(" * 欢迎使用学生学籍管理系统 *\n");
printf(" * *\n");
printf(" * *\n");
printf(" * *\n");
printf(" * 你可以进行一下选择 *\n");
printf(" * *\n");
printf(" * [1]输入学生信息 *\n");
printf(" * [2]修改学生信息 *\n");
printf(" * [3]删除学生信息 *\n");
printf(" * [4]查找学生信息 *\n");
printf(" * [5]输出学生信息 *\n");
printf(" * [6]退出当前程序 *\n");
printf(" * *\n");
printf(" * * * * * * * * * * * * * * * * **\n");
while(1)
{
printf(" 请输入你所需功能前的数字:[ ]\b\b");
num=getchar();getchar();
if(num>'0'&&num<'7')
break;
else
printf("输入错误,请重新输入\n");
}
return num;
}
文件存储可能有一些问题。