title: How to get user input in Unix C?
body: <p>I'm trying to code a program that can be used in the Unix environment.  However, this is my first time doing such a thing and I'm confused regarding some things. My code is as follows:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  
  #define BUFFSIZE 4096
  
  int main (int argc, char * argv[]){
  
  int n;
  char buf[BUFFSIZE];
  
  if (argc != 2){
      err_sys("usage a.out &lt;pathname&gt;");  
  }
  
  if (access(argv[1], R_OK) == -1){
      err_ret("access error for %s", argv[1]);
  }
  
  if (access(argv[2], R_OK) == 0){
      printf("Would you like to overwrite (Y or N)? \n");
      if(){
          exit(0);
      }
  }
  
  while ((n = read(STDIN_FILENO, buf, BUFFSIZE) &gt; 0)){
      if (write(STDOUT_FILENO, buf, n) != n){
          err_sys("write error"); 
      }
  }
  
  if (n &lt; 0){
      err_sys("read error");
  }
  
  close(STDOUT_FILENO);
  close(STDIN_FILENO);
  
  exit(0);
  
  }
  </code></pre>
  
  <p>Okay, so basically, I have to write a program that uses open, read, write, close, and access.  However, I'm completely confused on how to implement the part where I have to prompt the user to overwrite or not if the second argument (which is a file name) is already in place. </p>
  
  <p>Aka these lines of code:</p>
  
  <pre><code>if (access(argv[2], R_OK) == 0){
     printf("Would you like to overwrite (Y or N)? \n");
         if(){
             exit(0);
  }
  </code></pre>
  
  <p>I'm not exactly sure how to get the response from the user and what the condition would be.  </p>
  
  <p>Also, if any of my other code is wrong, feel free to inform me and let me know how I can improve it. </p>
  
  <p>Thank you!</p>
  
  <p>Just added:</p>
  
  <pre><code>if (open(argv[1], O_RDONLY) &lt; 0){
      err_ret("open error for %s", argv[1]);
  }
  </code></pre>