#include <stdio.h>

int main ()
{

char filename[] = "file.txt";
FILE * fp ;
fp = fopen(filename, "r");
if(fp == NULL)
{
printf("This file NOT exists");
return 0;
}
else
{
fp = fopen(filename, "r");
if(fp == NULL)
{
printf("This file is exists and can not reading \n");
}
else
{
printf("This file is exists and can reading ");
}
}

int ret;
char oldname[] = "file.txt";
char newname[] = "newfile.txt";

ret = rename(oldname, newname);

if(ret == 0)
{
printf("File renamed successfully\n");

}
else
{
printf("Error: unable to rename the file");
}

fclose(fp);
ret = 0;
ret = remove(newname);
if(ret == 0)
{
printf("File deleted successfully");
}
else
{
printf("Error: unable to delete the file");
}

return(0);
}