title: Bus Error: 10 in C Program, cannot figure out why
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  void split_line(char **fields, char *line);
  
  int main() {
      char *fields[5];
      char *line = "donuts,are,cool,and,tasty";
      int i = 0;
  
      split_line(fields, line);
  
      return 0;
  }
  
  void split_line(char **fields, char *line) {
      int i = 0;
      char *token, *delim;
      delim = ",\n";
      token = strtok(line, delim);
      while (token) {
          fields[i] = malloc(strlen(token));
          strcpy(fields[i], token);
          token = strtok(NULL, delim);
          i++;
      }
  
  }
  </code></pre>
  
  <p>I am new to C and have been trying to figure out how to fix this error for the better part of an hour. It compiles but at run-time I get</p>
  
  <blockquote>
    <p>Bus Error: 10.</p>
  </blockquote>
  
  <p>I would appreciate if anyone could lead me to why this is happening and what I am doing wrong.</p>