#include <unistd.h>
#include <fcntl.h>

void main()
{
  // 0 = stdin, 1 = stdout, 2 = stderr

  char array[256];
  int read_fd = open("./sample.txt", O_RDONLY);
  int write_fd = 2; // stdout

  int b = 1;

  // read the second half of the file by seeking to end
  // and rewinding to the midpoint.
  //          fd     offset   base
  b = lseek(read_fd,   0,    SEEK_END);
  b = lseek(read_fd, (b/2),  SEEK_SET);

  while(b > 0) {
    b = read(read_fd, array, 255);
    write(write_fd, array, b);
  }

  close(read_fd);
}