title: Moving file pointer back to string it already read
body: <p>I am trying to find specific word from a file and replace it with some other word.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
      FILE *fr;
      fpos_t pos;
  
      char temp[20];
  
      fr = fopen("filename_to_open","r+");
  
      while(!feof(fr)) {
          fgetpos(fr , &amp;pos);
          fscanf(fr, "%s", temp);
          if(strcmp(temp,"word_to_find") == 0) {
              fsetpos(fr, &amp;pos);
              fprintf(fr, "word_to_replace_with");
          }
      }
  }
  </code></pre>
  
  <p>After reading an string i am comparing it with an string. if it matches i want to replace it. I tried using fgetpos(), fputpos(), fseek(). i am not getting the desired output. how can i move filepointer back to exactly point it to string it already have read.</p>