file in use conflict

Hi all,

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.

this is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
bool bBool = true

while(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?

Thanks in advance!

Marco
I have no idea why that doesn't work but according to [http://www.cplusplus.com/reference/clibrary/cstdio/remove/] it should work if you close the file after you remove the file. You basically need write access.
Topic archived. No new replies allowed.