title: I can't figure this out the System call "read" function in c. ( K&R c language book)
body: <p>i'm new to C and this is even my first question to ask in "stackoverflow.com"
  If i'm doing something unpleasant, plz correct me :)</p>
  
  <p>SO, what i'm trying to understand is what is the real process of "read function".
  Let me specify my question in detail while explaining what i'm experimenting.
  Basic concept of my small program is that copy a file into screen.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #define BUF_SIZE 1000
  
  int main(int argc,char *argv[])
  { 
          int fd, n;
          char buf[BUF_SIZE];
          char *name;
          name = argv[1];
  
          fd = open(name, O_RDWR, 0);
  
  //------------whith while loop -----------------------
          //while( (n = read( fd, buf, BUF_SIZE)) &gt; 0 )
          //       {
          //              printf("?");
          //
          //              write(1, buf, n);
          //              printf("??");
          //       }
  
  // ------------without while loop ----------------
  
                n = read( fd, buf, BUF_SIZE);
                  printf("?");
                  write(1, buf, n);
                  printf("??");
  
          return 0;
  }
  </code></pre>
  
  <p><strong>First</strong>,(1) my question was "why do i need while loop for read() ?</p>
  
  <p>my understanding was that after i call the system call "read()" (i'm not sure if it's real system call or just function provided by C library which will call the real systemcall),
  it now gets buf[] and BUF_SIZE to fill out and it happened at one call. But then again, there should be a reason to put while loop..</p>
  
  <p>But <strong>The result</strong> of both are the same displaying the exact same content of file.</p>
  
  <p><strong>Second</strong>, (2) my question was if the system call "read" gets called several time till end of file, then how many time can get inside while loop calling "write function" (that's why i put printf("?") ).</p>
  
  <p><strong>But the result</strong> stroke ...
  It ignored my printf function whether it's called before "write" or after.</p>
  
  <p>I think there is very huge concept i'm missing.. I hope someone would really help me out :)
  Thank you in advance. </p>