title: Replace line in text-file using C
body: <p>I want to change lines which contain the <code>#</code> symbol in a text file with <code>heet</code> using C. </p>
  
  <p>I have tried it this way, but it did not work thoroughly, it just replaces the characters &amp; overwrites not the whole string, like I want.    </p>
  
  <p>Is there any other trick to remove or delete a whole line from the file? So, we can easily replace it.  </p>
  
  <p><strong>myfile.txt:</strong> <em>(before execution)</em></p>
  
  <pre><code>Joy
  #Smith
  Lee
  Sara#
  Priyanka
  #Addy
  </code></pre>
  
  <p><strong>Code:</strong>  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
      FILE *pFile;
      fpos_t pos1, pos2;
      int line = 0;
      char buf[68]
      char *p;
      char temp[10] = "heet";
  
      pFile = fopen("myfile.txt", "r+");
  
      printf("changes are made in this lines:\t");    
      while (!feof(pFile)) {
          ++line;
          fgetpos(pFile, &amp;pos1);          
  
          if (fgets(buf, 68, pFile) == NULL)  
              break;
  
          fgetpos(pFile, &amp;pos2);
  
          p = strchr(buf, '#');
  
          if (p != NULL) {
              printf("%d, " , line);
              fsetpos(pFile, &amp;pos1);  
              fputs(temp, pFile);
          }
          fsetpos(pFile, &amp;pos2);
      }
  
      fclose(pFile);
      return 0;
  }
  </code></pre>
  
  <p><strong>myfile.txt:</strong> <em>(after execution)</em>  </p>
  
  <pre><code>Joy  
  heetth  
  Lee  
  heet#  
  Priyanka  
  heety  
  </code></pre>
  
  <p><strong>Output:</strong>  </p>
  
  <pre><code>changes are made in this lines: 2, 4, 6,  
  </code></pre>
  
  <p><strong>myfile.txt:</strong> <em>(I want to get)</em>  </p>
  
  <pre><code>Joy  
  heet  
  Lee  
  heet  
  Priyanka  
  heet  
  </code></pre>