I've got a problem with deleting/overwriting a file using my program because the file is in use by my program because I use the same file to read data from.
bool bBool = truewhile(bBool){
//Run myprogram.exe tot generate output.txt
//Create file pointer and open file
FILE* pInputFile = NULL;
pInputFile = fopen("output.txt", "r");
//
//then I do some reading using fscanf()
//
//And when I'm done reading I close the file using fclose()
fclose(pInputFile);
//The next step is deleting the output.txt
if( remove( "output.txt" ) == -1 ){
//ERROR
}else{
//Succesfull
}
}
I use fclose() to close the file but the file remains in use by my program until it is totally shut down.
What is the solution to free the file so it can be deleted/overwrited?