Advertisement
Guest User

Compito

a guest
May 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define FILE1    "./hits.bin"
  4. #define FILE2    "./rette.bin"
  5. typedef int* pint;
  6. typedef FILE* pfile;
  7.  
  8.  
  9. typedef struct _dot
  10.   {
  11.    int x;
  12.    int y;
  13.   }dot;
  14.  
  15. typedef dot* pdot;
  16.  
  17. typedef struct _retta
  18.   {
  19.    float a;
  20.    float b;
  21.    float c;
  22.   }retta;
  23.  
  24. typedef retta* pretta;
  25.  
  26. int main(void)
  27.     {
  28.         pfile pf1;
  29.         int np, nr,i;
  30.         pretta pr;
  31.         pdot pd;
  32.        
  33.         if ((pf1=fopen(FILE1,  "rb"))==NULL) return EXIT_FAILURE;
  34.         fread(&np,sizeof(int), 1, pf1);
  35.         printf("%d \n",np);        
  36.        
  37.         if ((pd=(pdot)malloc(sizeof(dot)*np))==NULL) return EXIT_FAILURE;
  38.         fread(pd,sizeof(dot), np, pf1);
  39.         fclose(pf1);
  40.         for(i=0;i<np;i++,pd++)
  41.             {printf("%d %d \n",(*pd).x, (*pd).y);}
  42.        
  43.          if ((pf1=fopen(FILE2,  "rb"))==NULL) return EXIT_FAILURE;
  44.         fread(&nr,sizeof(int), 1, pf1);
  45.         printf("\n %d \n",nr);        
  46.        
  47.         if ((pr=(pretta)malloc(sizeof(retta)*nr))==NULL) return EXIT_FAILURE;
  48.         fread(pr,sizeof(retta), nr, pf1);
  49.         fclose(pf1);
  50.         for(i=0;i<nr;i++,pr++)
  51.             {printf("%f %f %f \n",(*pr).a, (*pr).b, (*pr).c);}
  52.        
  53.        
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement