Back

#include<stdio.h>
#include<fcntl.h>

int get(int fd, long pos, char *buf, int n);

int main(int argc, char *argv[])
{
   int fd, i=0;
   long pos;
   char buf[BUFSIZ];
  if (( fd = open(argv[1], O_RDONLY, 0)) == -1)
      printf("can't open %s", argv[1]);

 for(i=0; i<20; i+=2)
  { get(fd, 0L, buf, i);
    printf("%s\n",buf);
  }

 return 0;
}

int get(int fd, long pos, char *buf, int n)
{
  if (lseek(fd, pos, 0) >= 0)
    return read(fd, buf, n);
  else
    return -1;
}

Top