title: Unexpected character when printing char array
body: <p>I am trying to build a cron expression parser</p>
  
  <p>I have the following methods (Work in progress):</p>
  
  <pre><code>Cron parseCron(char* cronStr) {
    char *dup = strdup(cronStr);
    char* p;
    char* cronAtoms[5];
    int i = 0;
    p = strtok(dup, " ");
    while(p != NULL){
      p = strtok(NULL, " ");
      cronAtoms[i] = p;
      i++;
  
    }
    return generateCron(cronAtoms);
  
  }
  </code></pre>
  
  <p>and this one:</p>
  
  <pre><code>Cron generateCron(char **cronAtoms){
    Cron cron;
    for(int i = 0; i &lt; 5; i++) {
      printf("%s\n", cronAtoms[i]);
    }
    return cron;
  }
  </code></pre>
  
  <p>The input string is <code>"* * * * *"</code>
   when I print the results here's what I get:</p>
  
  <pre><code>*
  *
  *
  *
  @
  </code></pre>
  
  <p>I have to admit I am a bit surprised, but I think I understand why. The last pointer stored in the <code>cronAtoms</code> array might include the NULL terminating character or maybe some cruft in the adjacent memory. I am no C expert, so it's entirely possible I am wrong about my assumption.</p>
  
  <p>More importantly, I'd like to know a fool-proof way correctly extract the last character (have "*" instead of "@") </p>