title: Relationship between file descriptors, file pointers and file position indicators
body: <p>I am trying to understand how a file position indicator moves after I read some bytes from a file. I have a file named "filename.dat" with a single line: "abcdefghijklmnopqrstuvwxyz" (without the quotes).</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  
  
  int main () {
  
      int fd = open("filename.dat", O_RDONLY);
      FILE* fp = fdopen(fd,"r");
      printf("ftell(fp): %ld, errno = %d\n", ftell(fp), errno);
  
      fseek(fp, 5, SEEK_SET); // advance 5 bytes from beginning of file
      printf("file position indicator: %ld, errno = %d\n", ftell(fp), errno);
  
      char buffer[100];
      int result = read(fd, buffer, 4); // read 4 bytes 
      printf("result = %d, buffer = %s, errno = %d\n", result, buffer, errno);
      printf("file position indicator: %ld, errno = %d\n", ftell(fp), errno);
  
      fseek(fp, 3, SEEK_CUR); // advance 3 bytes 
      printf("file position indicator: %ld, errno = %d\n", ftell(fp), errno);
      result = read(fd, buffer, 6);  // read 6 bytes 
      printf("result = %d, buffer = %s, errno = %d\n", result, buffer, errno);
  
      printf("file position indicator: %ld\n", ftell(fp));
  
      close(fd);
      return 0;
  }
  
  
  ftell(fp): 0, errno = 0
  file position indicator: 5, errno = 0
  result = 4, buffer = fghi, errno = 0
  file position indicator: 5, errno = 0
  file position indicator: 8, errno = 0
  result = 0, buffer = fghi, errno = 0
  file position indicator: 8
  </code></pre>
  
  <p>I do not understand why the second time I try to use <code>read</code>, I get no bytes from the file. Also, why does the file position indicator not move when I read contents from the file using <code>read</code>? On the second <code>fseek</code>, advancing 4 bytes instead of 3 did also not work. Any suggestions?</p>