title: Trying to find and replace a string from file
body: <pre><code>    void replaceString(char* file, char* str, char* replace)
      {
          FILE* fp = fopen(file,&quot;rt&quot;);
          char buffer[BUFFER];
          while(fgets(buffer,BUFFER,fp)!=NULL)
          {
              char* s;
              s=strstr(buffer,str);
              if(s!=NULL)
              {
                  strcpy(s,replace);
                  printf(&quot;%s is replaced by %s\n&quot;,str,replace);
              }
          }
          fclose(fp);
      }
  
      int main(int argc, char **argv)
      {
          char* file= &quot;text.txt&quot;;
          replaceString(file,&quot;is&quot;,&quot;was&quot;);
          printFile(file);
          return 0;
      }
  </code></pre>
  <p>Guys I am new to file operations, trying to find and replace a string by another. please help! I am trying to open the file in &quot;rt&quot; mode. Saw this in some example code. Not sure about the mode. I am guessing that I need to use a temp.txt file to do that! Can it be done in a single file without using any other file?</p>