Advertisement
Kofa_Joh

Class_Work_26.04_my_work

Apr 26th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct exchangeRate
  6. {
  7.     float bynToUsd;
  8.     float usdToByn;
  9.     float bynToEur;
  10.     float eurToByn;
  11. };
  12.  
  13.  
  14. int main()
  15. {
  16.     struct exchangeRate* rate = malloc(sizeof(struct exchangeRate));
  17.     FILE* f = fopen("d:\\db.bin", "rb");
  18.    
  19.     if (f == NULL)
  20.     {
  21.         f = fopen("d:\\db.bin", "wb");
  22.  
  23.         rate->bynToUsd = 10;
  24.         rate->usdToByn = 11;
  25.         rate->bynToEur = 12;
  26.         rate->eurToByn = 13;
  27.  
  28.         fwrite(rate, sizeof(struct exchangeRate), 1, f);
  29.  
  30.         fclose(f);
  31.         return 0;
  32.  
  33.     }
  34.    
  35.         fread(rate, sizeof(struct exchangeRate),1, f);
  36.  
  37.         printf("%.4f\n", rate->bynToUsd);
  38.         printf("%.4f\n", rate->usdToByn);
  39.         printf("%.4f\n", rate->bynToEur);
  40.         printf("%.4f\n", rate->eurToByn);
  41.  
  42.     fclose(f);
  43.     free(rate);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement