title: Change current working directory in child process in C
body: <p>I have to write a program which generates child process than ends parent process and after that that created child process has to ask user to input new working directory, change it and print path to its new working directory. I wrote this, but scanf is not working ("It's not asking user to input something, program just ends) and the path is not changing... I've tried to set new directory to <code>char *newdirectory="home/usr/desktop"</code> and that didn't change working directory too</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/stat.h&gt;
  
  int main()
  {
      int pid;
      char directory[1024];
      char newdirectory[1024];        
      pid=fork(); 
      if(pid&lt;0)
      {
          printf("\n Error ");
          exit(1);
      }
      else if(pid==0)
      {
          printf("I'm child \n ");
          printf(" My PID: %d \n",getpid());
          getcwd(directory, sizeof(directory));
          printf(" My current working directory is: %s\n", directory);
          printf(" Enter the new path\n");
          scanf("%s", &amp;newdirectory);
          chdir(newdirectory);
          getcwd(directory, sizeof(directory));
          printf(" Path changed to: %s\n", directory);
          exit(0);
      }
      else
      {
          printf("I'm a parent \n ");
          printf("My PID is %d \n ",getpid());
          printf("Bye bye \n");
          exit(1);
      }
      return 0;
  }
  </code></pre>
  
  <p>Thank you for your time, effort and all the help to understand :)</p>