File open issue, after file deleted. fopen status is failing in VC++ RRS feed

  • Question

  • /* fopen example */
    #include <stdio.h>

    int _tmain(int argc, _TCHAR* argv[])
      FILE * pFile;
      for(int i=0; i < 1000000; i++)

                bool ret = remove("C:\\abc.txt");
                pFile = fopen ("C:\\abc.txt","w");
                if (pFile!=NULL)


                            fputs ("fopen example",pFile);
                            fclose (pFile);
                            printf("%d fopen() fails \n", count);
      return 0;

    Here, after remove is called, pFile = fopen ("C:\\abc.txt","w");is called,

    Sometimes even in C:\ the abc.txt file is not present after remove called, but the fopen pFile pointer is null.

    This is reproduced some times not always. In this example this issue is reproduced 50/60 times.

    Please suggest some solution.

    Friday, October 24, 2014 2:47 PM

All replies