/* priklad pr8_17.c citanie zo suboru vytvoreneho ulohou p7_13 (p2.txt)
prikazy tell a seek  */
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>

#define MAX 50

void main(void)
{
  int in1,lng;
  int pocet,min,max;
  float x,y;
  char line[MAX];

  if ((in1 = open("p2.txt",O_RDONLY)) == -1)
  {
    perror("Error ");
    printf("Can't open [p2.txt]\n");
    exit();
  }
  read(in1,&pocet,sizeof(pocet));
  read(in1,&min,sizeof(min));
  read(in1,&max,sizeof(max));
  printf("Pocet = %d\n",pocet);
  printf("Min = %d   Max = %d\n",min,max);
  max=tell(in1);
  printf("Poloha 1 v subore je %d\n",max);
  for(lng=0;lng<pocet+1;lng++)
  {
    read(in1,&min,sizeof(int));
    read(in1,line,min);
    line[min]='\0';
    printf("%d. %s",lng,line);
  }
  printf("Poloha 2 v subore je %d\n",tell(in1));
  lseek(in1,max,SEEK_SET);
  printf("Poloha (SEEK_SET) v subore je %d\n",tell(in1));
  lseek(in1,0L,SEEK_CUR);
  printf("Poloha (SEEK_CUR) v subore je %d\n",tell(in1));
  lseek(in1,0L,SEEK_END);
  printf("Poloha (SEEK_END) v subore je %d\n",tell(in1));
  close(in1);
}