title: reading linux sysfs for gpio with fgetc
body: <p>I write a simple program to read gpio using linux sysfs with no polling, but it seems when I want to read lower than three characters fgetc and fgets does not work correctly I wonder if this is only a bug or if I do mistaks in my code.</p>
  
  <pre><code>FILE* fd = fopen("/sys/class/gpio/gpio12/value", "rw+");
  if(!fd) {
      cerr &lt;&lt; "could not open the file." &lt;&lt; endl;
  }
  setbuf(fd, NULL);
  
  while(true) {
      if(fseek(fd, 0L, SEEK_SET)) {
          cerr &lt;&lt; "could not reposition the indicator" &lt;&lt; endl;
      }
  
      char val = fgetc(fd);
      cout &lt;&lt; val &lt;&lt; '\r';
  
      cout.flush();
  };
  </code></pre>
  
  <p>the above code  always return '0' even when I apply a high level voltage to gpio#12 but when I replace the fgetc and it's following line with these</p>
  
  <pre><code>    char str[3] = {0};
      fgets(str, 3, fd);
      cout &lt;&lt; str[0] &lt;&lt; 'r';
  </code></pre>
  
  <p>lines the program works correctly. on the other hand, the value file only contain one character '1' or '0' and one may think of using fgets with 2 or 1 character. in that case it does not work either. Could some one professional explain what happens there. what is wrong with the above code.
  I use g++ to compile the code and my gcc version is 4.6.3-14 armhf</p>