title: chdir(<directory>) doesn't change directory: No such file or directory
body: <p>I want to create a simple c++ programm, that changes directory.</p>
  <pre><code>int main(int argc, char * argv[]){
  //...
  char input[256];
  char *command;
  
  //read command
  fgets(input, 256, stdin);
  
  // CODE ADDED WITH HELP
  command = strchr(input, '\n');
      
  if(command){
      *command = '\0';
  }
  // CODE ADDED WITH HELP
  
  if(strncmp(input, &quot;cd &quot;,3)==0){
      strtok(input, &quot; &quot;);
      command = strtok(NULL, &quot;\0&quot;);
      if(chdir(command) != 0){
          perror(&quot;Error while changing directory. Please try again!&quot;);
      }
  }
  //...
  }
  </code></pre>
  <p>In the programm above you can see the code between the comment &quot;CODE ADDED WITH HELP&quot;. This was added after. The programm works now but I am trying to understand why it works now and why it didn't before.</p>
  <p>If you think the piece of code added away I was getting the error &quot;No such file or directory&quot; while trying to change directory. After I got some help and added a couple lines of code I can now successfully change directories.</p>
  <p>I am trying to understand what the piece of code exactly does in the context of what I am trying to achieve and why it doesn't work without it.</p>