title: Reading character devices in linux
body: <p>I read the device file /dev/hidraw0 when in the terminal by typing 
  cat /dev/hidraw0
  as the hidraw0 was the usb mouse, the output was a sequence of characters. This sequence was generated as I moved the mouse, clicked and scrolled.</p>
  
  <p>Then I also tried this with a C program. the code is,</p>
  
  <pre><code>include&lt;stdio.h&gt;
  
      int main()
      {
              FILE *ptr_file;
              char buf[1000];
  
              ptr_file =fopen("/dev/hidraw0","r");
              if (!ptr_file)
                  return 1;
  
              char c;
              while (1)
              {
                  c=fgetc(ptr_file);
                  if(c != NULL)
                      printf("%c",c);
                  else
                      printf(""); 
              }           
  
          fclose(ptr_file);
              return 0;
      }
  </code></pre>
  
  <p>this also generated the same (I suppose) sequence of characters. But in a very asynchronous manner. It didn't get updated as quickely as the cat /dev/hidraw0 command. </p>
  
  <p>Why this happens ?</p>