Problems with string reverse implementation
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1614723/why-is-this-c-code-causing-a-segmentation-fault">Why is this C code causing a segmentation fault?</a>  </p>
</blockquote>



<p>I am writing a simple string reverse script.  </p>

<p>I added print statements to debug.  I keep getting a run time exception before Error1.  But I can't seem to figure out the reason.</p>

<p>Here's my code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;

using namespace std;

int strlen(char* s){ 
  int i = 0;
  while(*s != '\0'){
    i++;
    s++;
  }
  return i;
}

void reverse(char* src){

  char* dest = src+strlen(src)-1;
  char temp;

  while(src &lt; dest){
    temp = *src;
    cout &lt;&lt; "Error0" &lt;&lt; endl;
    *src = *dest;
    cout &lt;&lt; "Error1" &lt;&lt; endl;
    *dest = temp;
    cout &lt;&lt; "Error2" &lt;&lt; endl;
    src++;
    dest--;
  }

}

int main (void){

  char* s = "Hello world";
  cout &lt;&lt; s &lt;&lt; endl;
  int i = strlen(s);
  cout &lt;&lt; i &lt;&lt; endl;
  reverse(s);
  cout &lt;&lt; s &lt;&lt; endl;

  getchar();
  return 0;
}
</code></pre>

<p>Here's my output:</p>

<pre><code>            Hello world
            11
            Error0
</code></pre>
