title: Removing a substring from a string in C
body: <p>I already have the code that removes a substring from a string (word) in C, but I don't understand it. Can someone explain it to me? It doesn't use functions from the standard library. I tried to analyze it myself, but certain parts I still don't understand - I put them in the comments. I just need to figure out how does this all work.</p>
  
  <p>Thanks!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  void remove(char *s1, char *s2);
  
  int main()
  {
     char s1[101], s2[101];
     printf("First word: ");
     scanf("%s", s1);
     printf("Second word: ");
     scanf("%s", s2);
     remove(s1, s2);
     printf("The first word after removing is '%s'.", s1);
  
     return 0;
  }
  void remove(char *s1, char *s2)
  {
     int i = 0, j, k;
     while (s1[i])       // ITERATES THROUGH THE FIRST STRING s1?
     {
         for (j = 0; s2[j] &amp;&amp; s2[j] == s1[i + j]; j++);   // WHAT DOES THIS LINE DO?
            if (!s2[j])           // IF WE'RE AT THE END OF STRING s2? 
               {
                   for (k = i; s1[k + j]; k++)   //WHAT DOES THIS ENTIRE BLOCK DO?
                      s1[k] = s1[k + j];
                      s1[k] = 0;
                }
            else
                i++;    // ???
      }
  }
  </code></pre>