title: Counting the amount of string tokens in C
body: <p>I need to make a program that will emulate the terminal of Linux. Since some system calls requires 1,2 or more arguments, I want to make sure that the number of parameters given are correct. I'm using <code>strtok()</code> to separate the call name from the arguments, but I need to know how many tokens <code>strtok()</code> created to compare it.</p>
  
  <p>Here's and example code:</p>
  
  <pre><code>char *comand = (char*) malloc(sizeof(char)*100);
  char *token;
  char *path1 = (char*) malloc(sizeof(char)*100);
  char *path2= (char*) malloc(sizeof(char)*100);
  
  
  
      fgets(comand, 100, stdin);
  
      printf( "\nYou entered: %s \n", comand);
  
      token = strtok(comand ," ");
  
      //Check the number of tokens and add a condition in each IF to match
  
      if (strcmp("ls",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
  
      }
      else if (strcmp("cat",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
  
      }
      else if (strcmp("cp",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
          token = strtok(NULL," ");
          strcpy(path2,token);
  
      }
      else if (strcmp("mv",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
          token = strtok(NULL," ");
          strcpy(path2,token);    
  
      }
      else if (strcmp("find",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
  
      }
      else if (strcmp("rm",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
  
      }
      else if (strcmp("mkdir",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
      }
      else if (strcmp("rmdir",token) == 0) {
          token = strtok(NULL," ");
          strcpy(path1,token);
      }
      else if (strcmp("quit",token) == 0) {
          exit(0);
      }
      else print("Number of parameters do not match);
  </code></pre>