title: Distinguishing between entered commands in C
body: <p>I am working on a project in C. It is a primitive file system shell and one of commands can either take in a string after it or not. Here is how I am reading in commands from <code>stdin</code>. (This way is specified by my instructor):</p>
  
  <pre><code>fsys* f = newFileSystem();
  char cmd[21];
  char path[1001];
  
  while(scanf("%s", cmd) &gt; 0){
      if(strcmp(cmd, "ls") == 0){
          // this is probably the wrong way to go about it but...
          if(fgets(path, 1001, stdin)){   // 1001 is max path length
              strtok(path, "\n");     // doesn't remove if path is only \n
                                      // fgets reads in \n character and it affects output 
                                      // later, so getting rid of it now
              strtok(path, " ");      // doesn't remove space between ls and path name
              fs_ls(f, path);
          }
      }
      else if(strcmp(cmd, "pwd") == 0){
          // prints path to cwd beginning at root
          fs_pwd(f);
      // some other commands in here
      else{
          printf("Command not recognized.");
      }
  }
  </code></pre>
  
  <p>So <code>ls</code> can either take in no path (defaults to current working directory) or can take in a path and list files and directories at that location. </p>
  
  <p>What can I write within the if statement "if(strcmp(cmd, "ls") == 0)" for the system to check if there is a path after ls or not and execute ls correctly? </p>