title: Why does my program return true as the result is expected to be false?
body: <p>I'm implementing the C &quot;strstr&quot; function in C. This function takes 2 string in parameter and tell whether or not, the 1st string contains the second one. However, while the result is expected to be false, it returns true. Could you give me an explanation, please ?</p>
  <p>Here is code :</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int searchStr(char *ch1, char *ch2);
  
  int searchStr(char *ch1, char *ch2)
  {
      int i = 0;
      int j = 0;
      while (i &lt; strlen(ch1) - 1)
      {
          while (j &lt; strlen(ch2) - 1)
          {
              if(i == strlen(ch1) - 1) 
              {
                  return 0;
              }
              else
              {
                if (ch1[i] == ch2[j])
              {
                  j++;
                  i++;
              }
              else
              {
                  if (j &gt; 0)
                  {
                      j = 0;
                  }
                  else
                  {
                      i++;
                  }
              } 
              }
          }
          return 1;
      }
  }
  
  int main()
  {
      printf(&quot;%d&quot;, searchStr(&quot;science&quot;, &quot;sh&quot;));
  
  } 
  </code></pre>
  <p>Regards</p>
  <p>YT</p>