title: Tokenizing input from getline
body: <p>I'm trying to use getline() to take input from the keyboard, store it in a string, tokenize it, then print the tokens. When I run this, I get a Segmentation Fault error on the the last iteration (the iteration that handles the last token from the input).</p>
  
  <pre><code>#define _POSIX_C_SOURCE 200809L
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;string.h&gt;
  
  ////////////////////////
  // Main Method        //
  ////////////////////////
  void main() {
      system("clear");
      int ShInUse = 1; // Represents if shell is in use
  
      char curpath[1024];   // holds current path to print with prompt
      char *UserCommand = NULL;
      size_t combytes = 100;
      UserCommand = (char *) malloc(combytes);
      char *tok;
  
      // Main loop that shell uses //
      while (ShInUse == 1) {
          getcwd(curpath, sizeof(curpath)); // Store initial working dir
          printf("gash:%s&gt;", curpath);   // print prompt
  
          getline(&amp;UserCommand, &amp;combytes, stdin);
          tok = strtok(UserCommand, " \n");   // Tokenize input
          if (tok == NULL ) {
              printf("Enter a command.\n");
          } else {
              // Exit command //
              if (strcmp(tok, "exit") == 0) {
                  ShInUse = 0;
              } else {
                  while (tok != NULL ) {
                      printf("You entered a command.\n");
                      printf("tok: %s\n", tok);
                      tok = strtok(NULL, " \n");
                  }
              }
          }
      }
      free(UserCommand);
  }
  </code></pre>
  
  <p>Any ideas as to what may be causing this? Debugging isn't an option for me at the moment.</p>