RT,在vc2010下,做的学生管理系统。没有采用链表。
已经找到所要修改的行,并且修改成功,在内存中已经看到修改后的结果,并用fflush写回文件。
但是文件就是没有改变,上代码,求帮助,已经卡在这一天半了。
#include"head_1.h"
void change_stu(int id,char name[20],float score)
{
FILE *fp2;
char str[20];
char a[20];
int ch2;
int i;
int j;
char *path2="E:\\wangdao\\C\\student system\\Usr_infor_t.txt";
fp2=fopen(path2,"r+");
ch2=0;
i=0;
printf("输入要修改的学生\n");
fflush(stdin);
scanf("%d",&i);
printf("按格式输入修改的数值\n");
while (!feof(fp2))
{
while(fscanf(fp2,"%d",&ch2)!=EOF)
{
if(i==ch2)
{
for(j=0;j<2;j++){
gets(str);}
fgets(a,20,fp2);
printf("%s\n",a);
strcpy(a,str);
fprintf(fp2,a);
fflush(fp2);
printf("%s\n",str);
break;
}else{
fgets(str,20,fp2);
}
}
break;
}
fclose(fp2);
system("pause");
}