#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define STRLEN     256
#define FILE_T_IDX "file1.txt"
#define FILEA      "filea.bin"
#define FILEB      "fileb.bin"
#define FILEOUT    "file2.txt"

typedef FILE*      pfile;

float get_float_from_file(pfile pf)
 {char s[STRLEN];
  fscanf(pf,"%s",s);
  return atof(s);
 }

float get_int_from_file(pfile pf)
 {char s[STRLEN];
  fscanf(pf,"%s",s);
  return atoi(s);
 }


int main(void)
 {pfile f1,f[2],fout;
  unsigned i=0,j;
  float    t=0,v,mt=0.0,st=0.0,mv=0.0,sv=0.0;
 

  if ((f1  =fopen(FILE_T_IDX,"r")) ==NULL) goto file_err;
  if ((f[0]=fopen(FILEA,     "rb"))==NULL) goto file_err;
  if ((f[1]=fopen(FILEB,     "rb"))==NULL) goto file_err;
  if ((fout=fopen(FILEOUT,   "w")) ==NULL) goto file_err;

  while((t=get_float_from_file(f1)))
   {i++;
    mt+=t;st+=t*t;
    j=get_int_from_file(f1);
    fread(&v,sizeof(float),1,f[j]);
    fprintf(fout,"(%.2f,%.2f)\n",t,v);
    mv+=v;
    sv+=v*v;
   }
  fclose(f1);fclose(f[0]);fclose(f[1]);fclose(fout);

  mt/=10;
  st=sqrt(st/10-mt*mt);
  printf("mt=%.2f st=%.2f\n",mt,st);
  mv/=10;
  sv=sqrt(sv/10-mv*mv);
  printf("mv=%.2f sv=%.2f\n",mv,sv);
   
  return EXIT_SUCCESS;
   
  file_err: printf("Problema col file!!\n");       return EXIT_FAILURE;
   
 }

