title: Illogical bus error from printf in C
body: <p>When I compile and run my code, I get a bus error right after it prints "starting."
  Here is what happens:</p>
  
  <p><em><strong>bash-3.2$ ./remDup</em></strong><br>
  <strong><em>starting</em></strong><br>
  <strong><em>Bus error</em></strong>  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  void removeDups(char* str) 
  {
      int len = strlen(str);
      int i = 0;
  
      for (i = 0; i &lt; len; i++) {
          char a = str[i];
          int k = i + 1;
          int c = 0;
          int j = 0;
  
          for (j = k; j &lt; len; j++) {
              if (a != str[j]) {
                  str[k] = str[j];
                  k++;
              } else c++;
          }
  
          len -= c;
      }
  
      str[len] = '\0';
  }
  
  int main(int argc, const char* argv[] )
  {
      char *str1 = "apple";
  
      printf("%s -&gt; ", str1);
      removeDups(str1);
      printf("%s\n ", str1);
  
      return 1;
  }
  </code></pre>