#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define SIZE 2
struct score_type
{
char score_name[11];
int score_value;
};struct student_type
{
char num[11];
char name[15];
int sum;
int ave;
struct score_type score[7];
};input()
{
FILE* fp1;
struct student_type student[SIZE];
int i,j;
int ave,sum;
sum=0;
printf("下面进行数据输入:\n");
for(i=0;i<SIZE;i++)
{
printf("\n第%d位学生:\n",i+1);
printf("学号:");
scanf("%s",student[i].num);
printf("\n姓名:");
scanf("%s",student[i].name);
printf("\n开始输入成绩:");
for(j=0;j<7;j++)
{
printf("\n科目名称:");
scanf("%s",student[i].score[j].score_name);
printf("\n科目分数:");
scanf("%d",&student[i].score[j].score_value);
}
sum=0;
for(j=0;j<7;j++)
sum=sum+student[i].score[j].score_value;
ave=sum/7;
student[i].sum=sum;
student[i].ave=ave;
} if((fp1=fopen("stu.cfg","w"))==NULL)
{
printf("can not open file\n");
return;
}
for(i=0;i<SIZE;i++)
{
if(fprintf(fp1,"%s%c%s%c%d%c%d%c",student[i].num,'\t',student[i].name,'\t',student[i].sum,'\t',student[i].ave,'\t')<0)
{
printf("file write error\n");
return;
}
for(j=0;j<7;j++)
{
if(fprintf(fp1,"%s%c%d%c",student[i].score[j].score_name,'\t',student[i].score[j].score_value,'\t')<0)
{
printf("file write error\n");
return;
}
}
fprintf(fp1,"%c",'\n');
}
fclose(fp1);}inquire()
{
FILE *fp;
char number[11];
struct student_type student[SIZE];
int i,j; fp=fopen("stu.cfg","r");
printf("请输入学号,进行查询:");
scanf("%s",number);
for(i=0;i<SIZE;i++)
{ fscanf(fp,"%s%s%d%d",student[i].num,student[i].name,&student[i].sum,&student[i].ave);
for(j=0;j<7;j++)
fscanf(fp,"%s%d",student[i].score[j].score_name,&student[i].score[j].score_value);
} for(i=0;i<SIZE;i++)
{
if(strcmp(number,student[i].num)==0)
{
printf("学生 %s 的资料为: 学号%s 总分%d 平均分%d\n",student[i].name,student[i].num,student[i].sum,student[i].ave);
printf("各科成绩为:\n");
for(j=0;j<7;j++)
printf("科目名称:%s 科目成绩:%d\n",student[i].score[j].score_name,student[i].score[j].score_value);
}
}
return;
}print(void) /*打印函数q*/
{}quit() /*退出系统函数*/
{
char choose5;
/*int chose;这一句取消*/
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(1);
textcolor(15);
clrscr();
clrscr();
gotoxy(8,2);
printf("您确定您要退出系统吗?y 或 n\n");
gotoxy(7,3);
printf("请选择:");
scanf("%s",&choose5);
switch(choose5)
{
case 'Y':
case 'y':exit(0);
break;
case 'N':
case 'n':sth();
/*choose(chose);改为下面一句*/
choose();
break;
default:clrscr();
window(1,1,80,25);
textbackground(7);
clrscr();
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(3);
textcolor(6);
clrscr();
gotoxy(13,2);
printf("按键错误!请重新选择");/*又忘了分号*/
getch();
quit();
}
}
changekl() /*密码修改函数*/
{
char *kk=(char *)malloc(9*sizeof(char));
/*char buf[1];取消这一句*/
/*int chose;取消这一句*/
FILE *fp1;
window(17,16,58,19);
textbackground(0);
clrscr();
window(16,15,56,18);
textbackground(1);
textcolor(15);
clrscr();
gotoxy(8,4);
cputs("(密码必须为一个八位数字!)");
gotoxy(14,2);
/*kk=(char*)getpass("请输入一新密码:");改为下一句*/
scanf("%s",kk);
gotoxy(14,2);
textcolor(14);
if(strlen(kk)!=8)
{
window(17,16,57,19);
textbackground(0);
clrscr();
window(16,15,56,18);
textbackground(1);
textcolor(14);
clrscr();
gotoxy(9,2);
cputs("您输入的密码不为八位数,退出!");
getch();
sth();
/*choose(chose);改为下一句*/
choose();
/*return;这一句不要*/
}
else
{
if((fp1=fopen("k.cfg","wb"))!=NULL)/*加入了几行代码*/
{
cputs("恭喜您!密码修改成功!");
fputs(kk,fp1);
/*buf[0]=0;
fwrite(&buf[0],1,1,fp1);取消这两句*/
fclose(fp1);
}
else
cputs(" 密码修改失败!"); getch();
sth();
/*choose(chose);改为下一句*/
choose();
}
printf("测试之用!运行到这儿了!\n");
/*if((fp1=fopen("k.cfg","w"))!=NULL)这一段都是无效的,你的程序走不到这儿,
挪到上面。
{
fputs(kk,fp1);
buf[0]=0;
fwrite(&buf[0],1,1,fp1);
fclose(fp1);
}
getch();
sth();
choose(chose);改为下一句
choose();
return;*/
}void InputPass(char pass[]) /*登录时输入密码的函数*/
{
char c;
int i,j;
for(i=0;i<8;i++)
{
c=getch();
if((int)c==8 && i>0)/*Backspace键的ASCII码为8,检测到它就回退一格*/
{
i-=2;
window(16,9,56,12);
textbackground(2);
textcolor(14);
clrscr();
gotoxy(13,2);
printf("输入密码:");
/* x=wherex();检测当前光标位置*/
for(j=0;j<i+1;j++)
printf("*");
}
else if((int)c==8 && i==0)/*回退到i=0时,恢复i并什么也不做*/
{
i--; }
else
{
pass[i]=c;
printf("*");
}
}
pass[8]='\0';/*设置字符串结尾空零*/
}sth()
{ window(1,1,80,25);
textbackground(7);
clrscr();
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(4);
textcolor(15);
clrscr();
gotoxy(13,2);
printf("按任意键继续!");
getch();
return;
}
/*choose(int choice)改为下一句*/ /*选择要进行作业的系统*/
choose()
{
int choice; /*增加这一句,以取消原来函数choose的形参choice*/
window(1,1,80,25);
textbackground(7);
textcolor(4);
clrscr();
gotoxy(1,3);
printf("1.修改密码;\n");
printf("2.输入并储存学生档案;\n");
printf("3.根据要求查询;\n");
printf("4.打印需要的资料;\n");
printf("5.退出;\n");
gotoxy(1,11);
printf("请输入你的选择:");
scanf("%d",&choice);
switch(choice)
{
case 1:changekl();
break;
case 2:input();
break;
case 3:inquire();
break;
case 4:print();
break;
case 5:quit();
break;
default:printf("选择错误!重新选择!");/*此处结尾忘了分号*/
getch();
break;
}
}main()
{
char password[9];
char kl[9]="88888888";
/*int i=0,chose;改为下一句*/
int i=0;
FILE *fp;
window(1,1,80,25);
textbackground(1);
clrscr();
window(17,10,58,13);
textbackground(0);
clrscr();
for(i=0;i<=2;i++)
{
window(16,9,56,12);
textbackground(2);
textcolor(14);
clrscr();
gotoxy(13,2);
printf("输入密码:");
/*scanf("%s",password);取消这一句*/
InputPass(password);
textcolor(4);
if((fp=fopen("k.cfg","rb+"))!=NULL)
{
fseek(fp,0,SEEK_SET);
fgets(kl,9,fp);
fclose(fp);
}
if(i==2&&strcmp(password,kl)!=0)
{
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,10,56,12);
textbackground(2);
textcolor(4);
clrscr();
gotoxy(13,2);
cputs("密码错误!!!退出!!!");
getch();
exit(0);
}
if(strcmp(password,kl)!=0)
{
gotoxy(13,2);
cputs("密码错误,再输入一次!");
getch();
/*Line 218 Col 9 Insert Indent Tab Fill Unind*/
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(2);
textcolor(14);
clrscr();
}
else
break;
}
textbackground(7);
window(1,1,80,25);
clrscr();
gotoxy(10,10);
cputs("********************************\n");
gotoxy(10,11);
cputs("您已经成功进入系统,按任意键继续!");
gotoxy(10,12);
cputs("********************************\n");
getch();
/*choose( chose);改为下一句*/
choose();
return;
}
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define SIZE 2
struct score_type
{
char score_name[11];
int score_value;
};struct student_type
{
char num[11];
char name[15];
int sum;
int ave;
struct score_type score[7];
};input()
{
FILE* fp1;
struct student_type student[SIZE];
int i,j;
int ave,sum;
sum=0;
printf("下面进行数据输入:\n");
for(i=0;i<SIZE;i++)
{
printf("\n第%d位学生:\n",i+1);
printf("学号:");
scanf("%s",student[i].num);
printf("\n姓名:");
scanf("%s",student[i].name);
printf("\n开始输入成绩:");
for(j=0;j<7;j++)
{
printf("\n科目名称:");
scanf("%s",student[i].score[j].score_name);
printf("\n科目分数:");
scanf("%d",&student[i].score[j].score_value);
}
sum=0;
for(j=0;j<7;j++)
sum=sum+student[i].score[j].score_value;
ave=sum/7;
student[i].sum=sum;
student[i].ave=ave;
} if((fp1=fopen("stu.cfg","w"))==NULL)
{
printf("can not open file\n");
return;
}
for(i=0;i<SIZE;i++)
{
if(fprintf(fp1,"%s%c%s%c%d%c%d%c",student[i].num,'\t',student[i].name,'\t',student[i].sum,'\t',student[i].ave,'\t')<0)
{
printf("file write error\n");
return;
}
for(j=0;j<7;j++)
{
if(fprintf(fp1,"%s%c%d%c",student[i].score[j].score_name,'\t',student[i].score[j].score_value,'\t')<0)
{
printf("file write error\n");
return;
}
}
fprintf(fp1,"%c",'\n');
}
fclose(fp1);}inquire()
{
FILE *fp;
char number[11];
struct student_type student[SIZE];
int i,j; fp=fopen("stu.cfg","r");
printf("请输入学号,进行查询:");
scanf("%s",number);
for(i=0;i<SIZE;i++)
{ fscanf(fp,"%s%s%d%d",student[i].num,student[i].name,&student[i].sum,&student[i].ave);
for(j=0;j<7;j++)
fscanf(fp,"%s%d",student[i].score[j].score_name,&student[i].score[j].score_value);
} for(i=0;i<SIZE;i++)
{
if(strcmp(number,student[i].num)==0)
{
printf("学生 %s 的资料为: 学号%s 总分%d 平均分%d\n",student[i].name,student[i].num,student[i].sum,student[i].ave);
printf("各科成绩为:\n");
for(j=0;j<7;j++)
printf("科目名称:%s 科目成绩:%d\n",student[i].score[j].score_name,student[i].score[j].score_value);
}
}
return;
}print(void) /*打印函数q*/
{}quit() /*退出系统函数*/
{
char choose5;
/*int chose;这一句取消*/
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(1);
textcolor(15);
clrscr();
clrscr();
gotoxy(8,2);
printf("您确定您要退出系统吗?y 或 n\n");
gotoxy(7,3);
printf("请选择:");
scanf("%s",&choose5);
switch(choose5)
{
case 'Y':
case 'y':exit(0);
break;
case 'N':
case 'n':sth();
/*choose(chose);改为下面一句*/
choose();
break;
default:clrscr();
window(1,1,80,25);
textbackground(7);
clrscr();
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(3);
textcolor(6);
clrscr();
gotoxy(13,2);
printf("按键错误!请重新选择");/*又忘了分号*/
getch();
quit();
}
}
changekl() /*密码修改函数*/
{
char *kk=(char *)malloc(9*sizeof(char));
/*char buf[1];取消这一句*/
/*int chose;取消这一句*/
FILE *fp1;
window(17,16,58,19);
textbackground(0);
clrscr();
window(16,15,56,18);
textbackground(1);
textcolor(15);
clrscr();
gotoxy(8,4);
cputs("(密码必须为一个八位数字!)");
gotoxy(14,2);
/*kk=(char*)getpass("请输入一新密码:");改为下一句*/
scanf("%s",kk);
gotoxy(14,2);
textcolor(14);
if(strlen(kk)!=8)
{
window(17,16,57,19);
textbackground(0);
clrscr();
window(16,15,56,18);
textbackground(1);
textcolor(14);
clrscr();
gotoxy(9,2);
cputs("您输入的密码不为八位数,退出!");
getch();
sth();
/*choose(chose);改为下一句*/
choose();
/*return;这一句不要*/
}
else
{
if((fp1=fopen("k.cfg","wb"))!=NULL)/*加入了几行代码*/
{
cputs("恭喜您!密码修改成功!");
fputs(kk,fp1);
/*buf[0]=0;
fwrite(&buf[0],1,1,fp1);取消这两句*/
fclose(fp1);
}
else
cputs(" 密码修改失败!"); getch();
sth();
/*choose(chose);改为下一句*/
choose();
}
printf("测试之用!运行到这儿了!\n");
/*if((fp1=fopen("k.cfg","w"))!=NULL)这一段都是无效的,你的程序走不到这儿,
挪到上面。
{
fputs(kk,fp1);
buf[0]=0;
fwrite(&buf[0],1,1,fp1);
fclose(fp1);
}
getch();
sth();
choose(chose);改为下一句
choose();
return;*/
}void InputPass(char pass[]) /*登录时输入密码的函数*/
{
char c;
int i,j;
for(i=0;i<8;i++)
{
c=getch();
if((int)c==8 && i>0)/*Backspace键的ASCII码为8,检测到它就回退一格*/
{
i-=2;
window(16,9,56,12);
textbackground(2);
textcolor(14);
clrscr();
gotoxy(13,2);
printf("输入密码:");
/* x=wherex();检测当前光标位置*/
for(j=0;j<i+1;j++)
printf("*");
}
else if((int)c==8 && i==0)/*回退到i=0时,恢复i并什么也不做*/
{
i--; }
else
{
pass[i]=c;
printf("*");
}
}
pass[8]='\0';/*设置字符串结尾空零*/
}sth()
{ window(1,1,80,25);
textbackground(7);
clrscr();
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(4);
textcolor(15);
clrscr();
gotoxy(13,2);
printf("按任意键继续!");
getch();
return;
}
/*choose(int choice)改为下一句*/ /*选择要进行作业的系统*/
choose()
{
int choice; /*增加这一句,以取消原来函数choose的形参choice*/
window(1,1,80,25);
textbackground(7);
textcolor(4);
clrscr();
gotoxy(1,3);
printf("1.修改密码;\n");
printf("2.输入并储存学生档案;\n");
printf("3.根据要求查询;\n");
printf("4.打印需要的资料;\n");
printf("5.退出;\n");
gotoxy(1,11);
printf("请输入你的选择:");
scanf("%d",&choice);
switch(choice)
{
case 1:changekl();
break;
case 2:input();
break;
case 3:inquire();
break;
case 4:print();
break;
case 5:quit();
break;
default:printf("选择错误!重新选择!");/*此处结尾忘了分号*/
getch();
break;
}
}main()
{
char password[9];
char kl[9]="88888888";
/*int i=0,chose;改为下一句*/
int i=0;
FILE *fp;
window(1,1,80,25);
textbackground(1);
clrscr();
window(17,10,58,13);
textbackground(0);
clrscr();
for(i=0;i<=2;i++)
{
window(16,9,56,12);
textbackground(2);
textcolor(14);
clrscr();
gotoxy(13,2);
printf("输入密码:");
/*scanf("%s",password);取消这一句*/
InputPass(password);
textcolor(4);
if((fp=fopen("k.cfg","rb+"))!=NULL)
{
fseek(fp,0,SEEK_SET);
fgets(kl,9,fp);
fclose(fp);
}
if(i==2&&strcmp(password,kl)!=0)
{
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,10,56,12);
textbackground(2);
textcolor(4);
clrscr();
gotoxy(13,2);
cputs("密码错误!!!退出!!!");
getch();
exit(0);
}
if(strcmp(password,kl)!=0)
{
gotoxy(13,2);
cputs("密码错误,再输入一次!");
getch();
/*Line 218 Col 9 Insert Indent Tab Fill Unind*/
window(17,10,58,13);
textbackground(0);
clrscr();
window(16,9,56,12);
textbackground(2);
textcolor(14);
clrscr();
}
else
break;
}
textbackground(7);
window(1,1,80,25);
clrscr();
gotoxy(10,10);
cputs("********************************\n");
gotoxy(10,11);
cputs("您已经成功进入系统,按任意键继续!");
gotoxy(10,12);
cputs("********************************\n");
getch();
/*choose( chose);改为下一句*/
choose();
return;
}
那没有用float的办法了吗?
那没有用float的办法了吗?
static void force_fpf()
{
float x, *y; /* Just declares two variables */
y = &x; /* Forces linkage of FP formats */
x = *y; /* Suppress warning message about x */
}这就OK了。