title: Implementation of simple_search_text
body: <p>I am implementing the simple_search_text using <code>C++</code>. The program runs fine for most of the input but when I make both the <code>strings</code> same, the output shows nothing and returns normally. This might be a bug but I am not able to find it. I tried following the control flow of the algorithm, but still with no success. I have given the implementation below.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstring&gt;
  using namespace std;
  int simple_text_search(const char* p, const char* q);
  int main(){
      if( int i = simple_text_search("ell", "ell")) //strings are not from standard input
          cout &lt;&lt; "Found at " &lt;&lt; i;
      return 0;
  }
  
  int simple_text_search( const char* p, const char* q){
      int m = strlen(p);
      int n = strlen(q);
      int i = 0;
      while(i + m &lt;= n) {
          int j = 0;
          while(q[i + j] == p[j]){
              j = j + 1;
              if(j == m)
                  return i;
          }
          i = i + 1;
      }
      return -1;
  }
  </code></pre>