/* priklad pr8_14.c zapis do suboru (p.txt) so zadanim nazvu suboru cez parametre*/
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>

#define MAX 10

void main(int argc, char *argv[])
{
  int in,out,lng;
  int pocet=1,min=1,max=99;
  float x[MAX],y[MAX];

  for(lng=0;lng<MAX;lng++)
  {
    x[lng]=lng+1;
    y[lng]=2.5+lng;
  }
  if (argc == 1) printf("Volanie: %s file1 file2\n",argv[0]);
  else if(argc == 2) printf("Volanie: %s file1 file2\n",argv[0]);
  else
  {
    if ((in = open(*++argv,O_RDONLY)) == -1)
    {
      perror("Error ");
      printf("Can't open [%s]\n",*argv);
      exit();
    }
    if((out=open(*++argv,O_CREAT|O_TRUNC|O_BINARY,S_IWRITE)) == -1)
    {
      perror("Error ");
      printf("Can't open [%s]\n",*argv);
      exit();
    }
    write(out,&pocet,sizeof(pocet));
    write(out,&min,sizeof(min));
    write(out,&max,sizeof(max));
    for(lng=0;lng<MAX;lng++)
    {
      write(out,&x[lng],sizeof(float));
      write(out,&y[lng],sizeof(float));
      printf("i=%d x=%f y=%f\n",lng,x[lng],y[lng]);
    }
    close(in); close(out);
  }
}