title: C read() and write() while loop
body: <p>Here is example code:</p>
  
  <pre><code>int nbajt; int buf[];
  
   // we opened file and get descriptor fd
  
   while ((nbajt = read(fd, buf, 5)) &gt; 0) {
          if (write(fd2, buf, nlbajt) == -1) {
              perror("ERROR");
              exit(1);
          }
      } 
  </code></pre>
  
  <p>I don't understand how it is working when we use while loop. How many times this loop will proceed? (times of the lengs of <code>buf</code>?). Will <code>nbajt</code> has only values of <code>1</code> or <code>0 + buf</code> file position will be changing 1 place after each loop step? So in first step we have <code>nlbajt = 1</code> and we take buf first position char and then write it to <code>fd2</code>?. On the end we have <code>nlbajt==0</code> so it means it's end of file? I would be grateful for checking if i am wrong.My main concern is how nbajt value is changing. How it is diffrent for this attitude:</p>
  
  <pre><code>nbajt = read(fd, buf, 5));
  write(fd2, buf, sizeof(a));
  </code></pre>