rename()不能在代码块中编译的C程序中工作

时间:2015-06-16 15:50:46

标签: c

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <string.h> 


FILE *fp,*fp1;
char  p_id[7],buf[7],family[15],cl[15],nm[20];
int flag3=0;


int main()
{       // unsigned char t='y';

        clrscr();
        fp=fopen("Product.txt","r+");
        fp1=fopen("product_id.txt","w+");
        puts("\t\t\t Remove Product Details");
        printf("\n User :");
        if(flag3==0)
            {
                printf("\n\n\n \t\t\t Enter Product ID :");
                scanf("%s",p_id);
            }
        else
            {
                printf("\n\n\n \t\t\t Re-Enter Product ID :");
                scanf("%s",p_id);
            }
                 fclose(fp);
        fp=fopen("Product.txt","r");
        fscanf(fp,"%s %s %s %s",buf,family,cl,nm);
        while(!feof(fp))
        {
        if(strcmp(p_id,buf)==0)
            {
                printf("\n\n\n \t\t\t product removed");
            }
        else
            {
                fprintf(fp1," %s %s %s %s\n",buf,family,cl,nm);
            }
                fscanf(fp,"%s %s %s %s",buf,family,cl,nm);

        }
        //printf("\n \n Do you want to remove more product ?(Y/N)");
        //scanf("%s",&t);
        fclose(fp1);
        fclose(fp);
        remove("Product.txt");
         int status= rename("product_id.txt","Product.txt");
         if(status==0)
         {
             printf("working");
        }
         else 
         {
             printf("not working");
         }  
        getch();
        return 0;


}

在此代码中,我尝试通过将更新的数据存储到另一个文件中来更新文件中的特定行,然后删除原始文件并重命名第二个文件.Updation工作正常但rename()不起作用。

0 个答案:

没有答案