system("cls");
another = 'y';
while(another == 'y')
{
printf("\nEnter name of employee to delete ");
scanf("%s",empname);
ft = fopen("Temp.dat","wb");
rewind(fp);
while(fread(&e,recsize,1,fp) == 1)
{
if(strcmp(e.name,empname) != 0)
{
fwrite(&e,recsize,1,ft);
}
}
fclose(fp);
fclose(ft);
remove("EMP.DAT");
rename("Temp.dat","EMP.DAT");
fp = fopen("EMP.DAT", "rb+");
printf("Delete another record(y/n)");
another = getche();
}
這是一個代碼中刪除從二進制文件中使用員工姓名在c中的條目!但是當我想刪除它的emp ID它不會刪除條目,但刪除文件的所有內容!錯誤刪除二進制文件中的條目
case '4':
system("cls");
another = 'y';
while(another == 'y')
{
printf("\nEnter employee id to delete ");
scanf("%d",&empid);
ft = fopen("Temp.dat","wb");
rewind(fp);
while(fread(&e,recsize,1,fp) == 1)
{
if(e.userid!=empid)
{
fwrite(&e,recsize,1,ft);
}
}
fclose(fp);
fclose(ft);
remove("EMP.DAT");
rename("Temp.dat","EMP.DAT");
fp = fopen("EMP.DAT", "rb+");
printf("Delete another record(y/n)");
another = getche();
}
v可定義'e','empname'和'empid'的定義? – 2013-05-05 11:59:53
只是猜測:你的'case'4''接着是擦除命令,並且在case'4''的末尾忘記了'break'。 – 2013-05-05 12:05:16
@AdamLiss e是一個對象,empname是char和empid是int – 2013-05-05 12:06:41