title: Converting char* to lower case throws segfault error
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1011455/is-it-possible-to-modify-a-string-of-char-in-c">Is it possible to modify a string of char in C?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a function to convert a char* to lower case. This is the function:</p>
  
  <pre><code>void toLower(char* word, int length)
  {
      int i;
  
      for(i = 0; i &lt; length; i++) {
          // this I can do
          // printf("%c", tolower(word[i]));
  
          // this throws segfault
          word[i] = tolower(word[i]);
      }
  }
  </code></pre>
  
  <p>When I call it like this from main, it throws a segfault error:</p>
  
  <pre><code>char* needle = "foobar";
  toLower(needle, strlen(needle));
  </code></pre>
  
  <p>I'm certain the issue is in the assignment here:</p>
  
  <pre><code>word[i] = tolower(word[i]);
  </code></pre>
  
  <p>But I can't seem to figure out the corect way to do it. I tried passing it as <code>char**</code>, or doing <code>*(word+i)</code>, but all cause the same issue.</p>