title: How do I parse strings with the newline character in C?
body: <p>I'm writing a shell and I'm using getline() with stdin from the keyboard to take commands. I'm having trouble tokenizing the inputs though. I tried using \n as a delimiter in the strtok() function, but it seems not to be working.</p>
  
  <p>For example, I included an if statement to check if the user typed "exit" in which case it will terminate the program. It's not terminating.</p>
  
  <p>Here's the code I'm using:</p>
  
  <pre><code>void main() {
  int ShInUse = 1;
  char *UserCommand;   // This holds the input
  int combytes = 100;
  UserCommand = (char *) malloc (combytes);
  char *tok;
  
  while (ShInUse == 1) {
     printf("GASh: ");   // print prompt
     getline(&amp;UserCommand, &amp;combytes, stdin);
     tok = strtok(UserCommand, "\n");
     printf("%s\n", tok);
  
     if(tok == "exit") {
        ShInUse = 0;
        printf("Exiting.\n");
        exit(0);
     }
  }
  </code></pre>