#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;
}
In this code I am trying to update a specific line in a file by taking updated data store it into another file and then remove original file and rename 2nd file .Updation is working properly but rename() is not working.
