title: Bus error thrown and don't understand why
body: <p>I'm getting a bus error when attempting to run this code. The goal of it is to replace certain letters with numbers, E's with 3's, O's with 0's and so on.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #define MAX_BUF 1024
  
  int main () {
  
  char buf[MAX_BUF];
  int length;
  // other stuff
  do {
      // read a line
      fgets(buf, MAX_BUF, stdin);
      // calculate its length
      int len = strlen(buf) - 1;
      // modify the line by switching characters
      char buf2[MAX_BUF];
      strcpy(buf2, buf);
      int i;
      for(i = 0; i &lt; length; i++){
              if (buf2[i] == 'E' || buf2[i] == 'e'){
                      buf2[i] = '3';
              }
              if (buf2[i] == 'I' || buf2[i] == 'i'){
                      buf2[i] = '1';
              }
              if (buf2[i] == 'O' || buf2[i] == 'o'){
                      buf2[i] = '0';
              }
              if (buf2[i] == 'S' || buf2[i] == 's'){
                      buf2[i] = '5';
              }
      }
      // print the modified line
      printf("%s", buf2);
  } while (length &gt; 1);
  }
  </code></pre>
  
  <p>Expected output from input of </p>
  
  <p>"The quick brown fox jumps over the lazy dog." is </p>
  
  <p>"Th3 qu1ck br0wn f0x jump5 0v3r th3 lazy d0g." </p>
  
  <p>But again, the program throws "Bus error" which I don't understand and don't know how to spot.</p>