title: read() system call does not return EOF
body: <p>I am trying to read all data from a file using open() system call. But I am having difficulties figuring out the end of file. The C EOF flag doesn't work. My program goes into an infinite loop. Here is the code. The file has less than 100 characters in it.</p>
  
  <pre><code>int main()
  {
   char buf[100] = {""};
   i = 0;
   int fd = open ("file1.txt", O_RDONLY);
   int bytesread = read (fd, &amp;buf[i], 1);
   char c = buf[i];
   while (c != EOF) {
      i++;
      int bytesread = read (fd, &amp;buf[i], 1);
      c = buf[i];
   }
  }
  </code></pre>