You are trying to delete a file that has just been created (why?).
If that fails, the file has probably not been created (does not exist).
But you don't know that because you are not checking if opening it was successful (
pFile
not
NULL
).
So you should check that first (and check also if the input file has been opened):
#include <errno.h> /* for perror() and/or errno */
FILE *fp = fopen(image.pgm,rb);
if (NULL == fp)
{
perror("Failed to open input file");
return;
}
char *filename = "text";
FILE pFile = fopen(filename,"wb");
if (NULL == pFile)
{
perror("Failed to open output file");
fclose(fp);
return;
}
if (remove(filename))
{
perror("Failed to delete output file");
return;
}
</errno.h>
A possible reason for failure are insufficient access rights (you did not specify a path so that the file will be created in the current working directory).