I am trying to remove a file in my C
program. So I first of all check whether the file exists and then if it does I use the remove function. Here is my code:
if (!(f = fopen(position, "r")))
{
system("cls");
printf("User does not exist! Please enter the user again: ");
}
else
{
status = remove(position);
/*Check if file has been properly deleted*/
if(status == 0)
{
printf("User deleted successfully.\n\n");
break;
}
else
{
printf("Unable to delete the user\n");
}
}
Surely if the file definitely exists there should be no problem with removing the file. Anyway this bit of code is not working. And I just get returned "Unable to delete the user"
I have also tried using unlink along with importing unistd.h
but no luck.
What am I doing wrong?