void deleteRecord()
{
FILE *fp, *fdel;
struct person obj;
char number[20];
printf("\n============================");
printf("\n DELETE");
printf("\n============================\n\n");
fflush(stdin);
printf("Enter student number to delete :");
scanf("%s", number);
fp=fopen("D:\\data.txt","r");
fdel=fopen("D:\\del.txt","w");
while(fscanf(fp,"\n%s\n%s %s\n%s\n%s\n%s\n%s\n%s\n%s\n",
obj.stdNumb, obj.firstName, obj.lastName, obj.icPass,
obj.nationality, obj.gender, obj.dateOfBirth,
obj.contact, obj.address)==1)
if(stricmp(number, obj.stdNumb)!=0)
fprintf(fdel, "\n%s\n%s %s\n%s\n%s\n%s\n%s\n%s\n%s\n",
obj.stdNumb, obj.firstName, obj.lastName, obj.icPass,
obj.nationality, obj.gender, obj.dateOfBirth, obj.contact,
obj.address);
fclose(fp);
fclose(fdel);
remove("D:\\data.txt");
rename("D:\\del.txt","D:\\data.txt");
printf("Successully Deleted.");
getch();
}
这是我的完整代码,我删除了;
一段时间后,我删除了fgetc
,如果我运行并删除记录,它将删除所有记录..它仍然没有指定..如何解决这个问题?