我正在尝试删除一条记录,但我不知道如何。
P.S。此代码可以运行,我要删除的记录将写在* file1中,但我要删除的记录不会在* file中消失。
void del_shoes(int a)
{
FILE *file, *file1;
int flag=1,res,x;
file= fopen("shoes.txt","rb");
system("cls");
printf("Delete Items\n");
printf("Enter Item Code: ");
scanf("%d",&x);
rewind(file);
while (fread(&gds,sizeof (gds),1,file))
{
if(gds.code==x){
flag=0;
break;
}
}
if(flag==0)
{
file1=fopen("goods1.txt","ab");
file=fopen("shoes.txt","rb");
rewind(file);
while (fread(&gds,sizeof (gds),1,file))
{
if(gds.code!=x)
{
fwrite(&gds,sizeof(gds),1,file1);
}
}
printf("---item deleted---");
}
fclose(file1);
fclose(file);
file=fopen("shoes.txt","w");
fclose(file);
getche();
admin();
}