|
|
|
@ -64,6 +64,7 @@ void main() /*
|
|
|
|
|
void type() /*定义录入学生信息函数*/
|
|
|
|
|
{
|
|
|
|
|
int i; /*定义局部变量*/
|
|
|
|
|
n=openl(); /*调用openl函数*/
|
|
|
|
|
printf("\t\t输出你想输入的学生信息个数:");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
@ -99,7 +100,7 @@ void save() /*
|
|
|
|
|
printf("不能打开文件!\n");
|
|
|
|
|
return; /*终止程序*/
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i
|
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
|
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
|
|
|
|
|
printf("文件写入错误\n");
|
|
|
|
|
fclose(fp); /*关闭文件*/
|
|
|
|
@ -124,10 +125,11 @@ void search_name() /*
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char name[20]; /*声明字符数组*/
|
|
|
|
|
n=openl();
|
|
|
|
|
printf("\t\t\t请输入学生姓名:\n");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
|
for(i=0;i
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
if(strcmp(stu[i].name,name)==0) /*将输入的姓名与结构体中的姓名进行比较*/
|
|
|
|
|
{
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
@ -140,10 +142,11 @@ void search_number() /*
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char number[15]; /*声明字符数组*/
|
|
|
|
|
n=openl();
|
|
|
|
|
printf("\t\t\t请输入学号:\n");
|
|
|
|
|
scanf("%s",number);
|
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
|
for(i=0;i
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
if(strcmp(stu[i].num,number)==0) /*将输入的学号与结构体中的学号进行比较*/
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
@ -155,22 +158,22 @@ void order() /*
|
|
|
|
|
int i,j;
|
|
|
|
|
char a;
|
|
|
|
|
struct student temp; /*声明结构体变量*/
|
|
|
|
|
n=openl();
|
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
|
for(i=0;i
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
for(j=i+1;j
|
|
|
|
|
if(stu[i].sum
|
|
|
|
|
for(j=i+1;j<n-1;j++)
|
|
|
|
|
if(stu[i].num>stu[j].num)
|
|
|
|
|
{
|
|
|
|
|
temp=stu[i];
|
|
|
|
|
stu[i]= stu[j];
|
|
|
|
|
stu[j]=temp;
|
|
|
|
|
}
|
|
|
|
|
printf("%10s\t%s\t%2s\t%d\t%d\t%d\t%3.1f\t\t%6.1f\n",stu[i].num,stu[i].name,
|
|
|
|
|
stu[i].sex,stu[i].english,stu[i].math,stu[i].chinese,stu[i].aver,stu[i].sum);
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
|
}
|
|
|
|
|
getch();
|
|
|
|
|
printf("是否保存?(y or n)");
|
|
|
|
|
getchar();
|
|
|
|
|
scanf("%c",&a);
|
|
|
|
|
if(a=='y') /*是否保存排序后的文件*/
|
|
|
|
|
save();
|
|
|
|
@ -183,10 +186,11 @@ void del() /*
|
|
|
|
|
int i;
|
|
|
|
|
char a;
|
|
|
|
|
char name[20];
|
|
|
|
|
n=openl();
|
|
|
|
|
printf("\t\t\t输入学生名字:\n");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
|
for(i=0;i
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
if(strcmp(stu[i].name,name)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
@ -197,14 +201,14 @@ void del() /*
|
|
|
|
|
scanf("%c",&a);
|
|
|
|
|
if(a=='y') /*是否删除该信息*/
|
|
|
|
|
{
|
|
|
|
|
for(;i
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
stu[i]=stu[i+1];
|
|
|
|
|
n=n-1;
|
|
|
|
|
printf("你已经删除信息");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("退出")
|
|
|
|
|
getch();
|
|
|
|
|
printf("退出");
|
|
|
|
|
getchar();
|
|
|
|
|
}
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
@ -230,74 +234,11 @@ void see() /*
|
|
|
|
|
printf("按任意键查看!\n");
|
|
|
|
|
getch();
|
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
|
for(i=0;i
|
|
|
|
|
if(strcmp(stu[i].name,name)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
|
getch();
|
|
|
|
|
printf("真的删除?(y or n)");
|
|
|
|
|
getchar();
|
|
|
|
|
scanf("%c",&a);
|
|
|
|
|
if(a=='y') /*是否删除该信息*/
|
|
|
|
|
{
|
|
|
|
|
for(;i
|
|
|
|
|
stu[i]=stu[i+1];
|
|
|
|
|
n=n-1;
|
|
|
|
|
printf("你已经删除信息");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("退出");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
int openl() /*定义打开文件函数*/
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("student.txt","rb"))==NULL)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("Cannot open file.\n");
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
|
|
|
|
|
|
fread(&stu[i],sizeof(struct student),1,fp);
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
return(i-1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void see() /*打开并查看文件*/
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
n=openl();
|
|
|
|
|
|
|
|
|
|
printf("文件打开成功!\n");
|
|
|
|
|
|
|
|
|
|
printf("按任意键查看!\n");
|
|
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
|
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
|
|
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
|
}
|
|
|
|
|
printf("\n\n\n\t\t\t按任意键返回菜单");
|
|
|
|
|
getchar();
|
|
|
|
|
}
|