Okay, so this is the function I'm using remove()
:
int fmove(const char * filepth, const char * destpth)
{
FILE * fp;
fp = fopen(filepth, "r+");
FILE * fpdest;
fpdest = fopen(destpth, "w");
if ((fp != NULL) && (fpdest != NULL))
{
char fpdata[999];
fgets(fpdata, 999, fp);
fputs(fpdata, fpdest);
remove(filepth);
} else
{
prtmessage("ERROR", "Cannot move file!");
return 1;
}
return 0;
}
but the remove()
returns -1. I know that arrays return their pointers (am I telling it right?), but is there a way to pass the string in the filepath
to remove()
?
From the C Standard
If the file is open, the behavior of the remove function is implementation-defined.
You need to close the file before calling remove()
.