title: Why system call read() does not work when using user input
body: <p>It`s a file copying program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int fd1,fd2, ndata;
      char data[128];
      char *openname[1], *creatname[1]; 
  
      write(1, "Write open file name\n", 24); //user input
  
      read(0, openname, 30 );
  
      write(1, "Write creat file name\n", 25); //user input
  
      read(0, creatname,30);
  
      if((fd1 = open(openname, 0666))&lt;0)
          {
              perror("cannot open the file");
              exit(1);
          }
  
      if((fd2 = creat(creatname,0666))&lt;0)
          {
              perror("cannot create the file");
              exit(1);
          }
  
      while((ndata = read(fd1, data, 128))&gt;0)
          {
              if((write(fd2, data, ndata))!=ndata)
                  {
                      perror("cannot write the file");
                      exit(1); 
                  } 
          }
  
      close(fd1);
      close(fd2); 
  
      write(1, "File copy is done.",19);
  
      return 0;
  
  }
  </code></pre>
  
  <p>This code ain`t work. This code print the error message: </p>
  
  <pre><code>cannot open the file.
  </code></pre>
  
  <p>but if i change the code to this : </p>
  
  <pre><code>if((fd1 = open("copy.c", 0666))&lt;0)
  </code></pre>
  
  <p>and this :  </p>
  
  <pre><code>if((fd2 = creat("real.c",0666))&lt;0) 
  </code></pre>
  
  <p>worked well. </p>
  
  <p>Why this error happend? Please answer.</p>