/* priklad pr8_13.c zapis a citanie v rezime text, binarny a na nižšej úrovni IO
porovnanie prístupu k súboru   */
#include "stdio.h"
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>

void main(void)
{
  FILE *fp;
  char c[2];
  int pocet=1,h;

  fp = fopen("SS.TXT","w");
  if (fp == NULL) printf("File SS.TXT doesn't exist\n");
  else
  {
    fprintf(fp,"%d",pocet);
    fclose(fp);
  }
  fp = fopen("SS.TXT","rb");
  if (fp == NULL) printf("File SS.TXT doesn't exist\n");
  else
  {
    fscanf(fp,"%d",&pocet);
    fclose(fp);
  }
  printf("Pocet (text) = %d\n",pocet);
  fp = fopen("SS.TXT","rb");
  if (fp == NULL) printf("File SS.TXT doesn't exist\n");
  else
  {
    fread(c,sizeof(pocet),1,fp);
    fclose(fp);
  }
  sscanf(c,"%d",&pocet);
  printf("Pocet (blok) = %d c=%c%c\n",pocet,c[0],c[1]);
  h = open("SS.TXT",O_RDONLY);
  if (h == -1) printf("File SS.TXT doesn't exist\n");
  else
  {
    read(h,c,sizeof(pocet));
    close(h);
  }
  sscanf(c,"%d",&pocet);
  printf("Pocet (IO uroven) = %d c=%c%c\n",pocet,c[0],c[1]);
}