lyq7713 2014-07-15 07:00 采纳率: 0%
浏览 4208

调用文件重命名函数rename失败,errno的值为17,如何解决?

void onMenuDele(char *id)
{
FILE *p=fopen("f:\employee.txt","r"); //打开文件
if(p==NULL)
{
printf("Sorry!employee.txt cannot open!\n");
return ;
}

FILE *fp2=fopen("f:\\employ.txt","w+");     //创建临时文件
if(fp2==NULL)
{
    printf("Sorry!employ.txt cannot open!\n");
    return ;
}

char s[68];
char t[4],*q=id;

while(!feof(p))
{  
    fgets(s,68,p);
    if(!feof(p))
    {
        int count=0;
        id=q;

        for(int i=3,j=0;i<=6,j<4;i++,j++)
        {
            t[j]=s[i];
            if(t[j]==*id)
            {
                id++;
                count++;
            }
        }

        if(count!=4)
            fprintf(fp2,"%s",s);
    }
} 

fclose(p);
fclose(fp2);

/*if(remove("f:\\employee.txt")==0)
    printf("The file has been deleted!\n");
else
    printf("Sorry!The file cannot be deleted!\n");

if(rename("f:\\employ.txt","f:\\employee.txt")==0)
    printf("The file has been renamed!\n");
else
    printf("Sorry!The file cannot be renamed!\n");*/
int re_remove=remove("f:\\employee.txt");
int re_rename=rename("f:\\employ.txt","f:\\employee.txt");
printf("re_remove=%d",re_remove);
printf("re_rename=%d",re_rename);

int errno_t=errno;
printf("errno=%d",errno_t);

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
    • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
    • ¥30 c#打开word开启修订并实时显示批注
    • ¥15 如何解决ldsc的这条报错/index error
    • ¥15 VS2022+WDK驱动开发环境
    • ¥30 关于#java#的问题,请各位专家解答!
    • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
    • ¥20 pcf8563时钟芯片不启振
    • ¥20 pip2.40更新pip2.43时报错
    • ¥15 换yum源但仍然用不了httpd