gpt4 book ai didi

c - c中的remove()函数给出错误?

转载 作者:行者123 更新时间:2023-12-03 05:19:39 24 4
gpt4 key购买 nike

以下函数获取一个名称并从名为 All.bin 的二进制文件中删除该名称。据我所知,它工作正常,但删除功能总是给出错误

 void del(char *name)
{
struct database d; //strucutre variable containing name and meaning
FILE *p, *q;
p = fopen("All.bin","r"); //original file
q = fopen("temp.bin","w"); // temp file
while(fread(&d,sizeof(d),1,p))
if(strcmp(d.name,name) != 0)
fwrite(&d,sizeof(d),1,q);
fclose(p);
fclose(q);
if(remove("All.bin")!=0) //PROBLEM
printf("Error");
if(rename("temp.bin","All.bin")!=0)
printf("Error@");
getch();
}

最佳答案

这对我来说效果很好。创建 All.bin 文件后更改文件权限

关于c - c中的remove()函数给出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15675774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com