title: strcpy() Delete everything else
body: <p>I need to read a file and look for a word and replace with a new word but it's not working as it should:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  
  int main() {
  
  FILE * f = fopen("text" , "rb" );
  if(f == NULL ){
     perror("error ");
     return 1;
  }
  char chain[100];
  while(!feof(f)){
      fgets(chain, 100 , f);
  
  }
  printf("%s", chain);
  fclose(f);
  printf("\n \n ;D \n");
  return 0;
  }
  </code></pre>
  
  <p>And this is how I replace the old word:</p>
  
  <pre><code>char str[] ="This is a hiall samplesss friends string";
  char * pch;
  pch = strstr (str,"hiall");
  strncpy (pch,"sam",5);
  puts (str);
  </code></pre>
  
  <p>thanks</p>