title: Printf printing garbage after read() call. The offset is always printed as 0
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;stdint.h&gt;
  
  int main()
  {
      int file;
      off_t offset;
  
      if((file=open("testfile.txt",O_RDONLY)) &lt; -1)
              return 1;
  
      char buffer[19];
  
      if(read(file,buffer,19) != 19)  return 1;
      fprintf(stdout,"%s\n",buffer);
  
  
      if(offset = lseek(file,-19,SEEK_END) &lt; 0) return 1;
      fprintf(stdout,"%jd\n",(intmax_t)offset);
  
      if(read(file,buffer,19) != 19)  return 1;
      fprintf(stdout,"%s\n",buffer);
  
      return 0;
  }
  </code></pre>
  
  <p>The Output is as follows:</p>
  
  <p>This is a test file��</p>
  
  <p>0</p>
  
  <p>his is a test file</p>
  
  <p>��</p>
  
  <p>testfile.txt :</p>
  
  <p>This is a test file Testing how SEEK_END works This is a test file</p>
  
  <p>I have tried different formatting for offset, such as %ld,%d, but the output is still the same.
  Can't figure out why garbage appears at the end of first line and last line. Please help.</p>