title: Deleting Elements of a file in vc++
body: <pre><code>CStringArray myArray;
  myArray.copy(copiedsomeelements);
  CString file1="myfile1";
  CString file2="myfile2";
  FILE *fp1,*fp2;
  CString linetocompare="mytext";
  fp1 = fopen(myfile1, "rb");
  fread(data, 1280, 1, fp1);
  fclose(fp1);
  TCHAR * pch = _tcstok(data, _T("\r\n"));
  
  
  fp2 = fopen(myfile2, "w"); //open new file
  
  for (int m = 0; m &lt; myArray.GetCount(); m++)
  {
          CString temp(pch);
          if (strcmp(myArray.GetAt(m), linetocompare) != NULL)
          {
                  fprintf(fp2, "%s", temp); 
                  fwrite("\r\n", 1, 1, fp2);
          }
          pch = _tcstok(NULL, _T("\r\n"));
  }
  fclose(fp2);
  remove(myfile1); //remove old file
  rename(myfile2, myfile1);
  </code></pre>
  
  <p>The above code that works fine for me but not all the time. Sometimes it writes the "myfile2" as it is without comparing "linetocomapare" element.
  Please help me with this.
  Let me know if any clarifications are required. Thank you.</p>