title: Error : segmentation fault , core dumped , in c programming
body: <p>the following  c programming code gives a core dump segmentation fault , please tell me why i am getting this error and  help me by giving a corrected version of this code .Thank you!</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
   
  int main()
  {
      char str[100], ch;
      int i, Flag;
      Flag = 0;
   
      printf(&quot;\n Please Enter any String :  &quot;);
      fgets(str,sizeof(str),stdin);
      printf(&quot;%s&quot;,str);
      printf(&quot;\n Please Enter the Character that you want to replace with :  &quot;);
      scanf(&quot;%c&quot;, &amp;ch);
      
      for(i = 0; i &lt;= strlen(str); i++)
      {
            str[i]=ch;    
        }
      str[i]='\0';
      
      printf(&quot;\n The characters have been found and replaced with %c and they occur %d times &quot;, ch, i + 1);
      printf(&quot;The replaced string is %s &quot;,str);
      
      return 0;
  }
  </code></pre>