C语言实习:学生成绩管理系统(6)
发布时间:2021-06-07
发布时间:2021-06-07
void shuru() {
if((fp=fopen("s_score.txt","ab+"))==NULL) /*以读写方式打开名为s_score的文件*/ {
printf("cannot open this file.\n"); getch();exit(0); }
for(i=0;i<=1000;i++) {
printf("\nPlease shuru xuehao:"); gets(data.xuehao);
printf("Please shuru mingzi:"); gets(data.mingzi);
printf("please shuru nianling:"); gets(data.nianling);
printf("Please shuru shuxue score:"); gets(temp);data.score[0]=atof(temp); printf("Please input yingyu score:"); gets(temp);data.score[1]=atof(temp); printf("Please shuru wuli score:"); gets(temp);data.score[2]=atof(temp);
data.score[3]=data.score[0]+data.score[1]+data.score[2]; fwrite(&data,sizeof(data),1,fp); printf("another?y/n"); ch=getch();
if(ch=='n'||ch=='N') break;
} fclose(fp); }
3. 修改模块:
[分析]:用户输入要修改学生的学号,根据学生的学号查找学生记录,并提示用户修改该记录的哪部分信息.根据用户选择修改相应的信息. [流程图]:
Y N
[程序]:
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL) /*检查是否出错*/ {
printf("Cannot open this file.\n"); exit(0); }
printf("\nPLease shuru xiugai xuehao:"); scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1) {
j=atoi(data.xuehao); if(j==i) {
printf("xuehao:%s\nmingzi:%s\nnianling:%s\n",data.xuehao,data.mingzi,data.nianling);
printf("Please shuru mingzi:"); gets(data.mingzi);
printf("Please shuru shuxue score:"); gets(temp);data.score[0]=atof(temp); printf("Please input yingyu score:"); gets(temp);data.score[1]=atof(temp); printf("Please input wuli score:"); gets(temp);data.score[2]=atof(temp);
data.score[3]=data.score[0]+data.score[1]+data.score[2];
} fwrite(&data,sizeof(data),1,fp1); }