title: Read a line from text file and delete it
body: <p>I want to read a text file line by line, perform some checks, and if the line is not required, delete it.
  I have done the code for reading line, but I don't know how to delete that line if it is not required by me.
  Please help me find the simplest method for deleting the line.
  Here is my code snippet what I tried:</p>
  
  <pre><code>   char ip[32];
     int port;
     DWORD dwWritten;
     FILE *fpOriginal, *fpOutput;
     HANDLE hFile,tempFile;
     hFile=CreateFile("Hell.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
     tempFile=CreateFile("temp.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
     WriteFile(hFile,"10.0.1.25 524192\r\n\r\n10.0.1.25 524193\r\n\r\n",strlen("10.0.1.25 524192\r\n\r\n10.0.1.25 524193\r\n\r\n"),&amp;dwWritten,0);
     fpOriginal = fopen("Hell.txt", "r+");
     fpOutput = fopen("temp.txt", "w+");
  
     while (fscanf(fpOriginal, " %s %d", ip, &amp;port) &gt; 0) 
        {
           printf("\nLine1:");
           printf("ip: %s, port: %d", ip, port);
           char portbuff[32], space[]=" ";
           sprintf(portbuff, "%i",port);
           strcat(ip," ");
           strcat(ip,portbuff);
           if(port == 524192)
              printf("\n Delete this Line now");
           else
              WriteFile(tempFile,ip,strlen(ip),&amp;dwWritten,0);
        }
  
       fclose(fpOriginal);
       fclose(fpOutput);
       CloseHandle(hFile);
       CloseHandle(tempFile);
       remove("Hell.txt");
       if(!(rename("temp.txt","Bye.txt")))
       {
           printf("\ncould not rename\n");
       }
       else 
          printf("\nRename Done\n");
       //remove ("Hell.txt");
  </code></pre>