Advertisement
Patresss

Untitled

Sep 2nd, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void zapisz(float tab[],char *fbinname, char *ftextname)
  4. {
  5. int i;
  6.     FILE *plik_b=fopen(fbinname,"wb");
  7.     fwrite(tab,5,sizeof(float),plik_b);
  8.     fclose(plik_b);
  9.  
  10.     FILE *plik_t=fopen(ftextname,"w");
  11.     for(i=0;i<5;i++){
  12.     fscanf(plik_t,"%f",&tab[i]);
  13.     }
  14. }
  15.  
  16. int main(void){
  17. float tab[5]={1.0,2.0,3.2,4.4,5.5};
  18. float tab2[5];
  19. char fbinname[10]="plik.bin";
  20. char ftextname[10]="plik.txt";
  21. int i;
  22. zapisz(tab, fbinname,ftextname);
  23.  
  24. FILE *plik_br=fopen(fbinname,"rb");
  25. fread(tab2,5,sizeof(float),plik_br);
  26. fclose(plik_br);
  27. puts("Z binarnego:");
  28. for(i=0;i<5;i++)
  29.     printf("%f\n",tab2[i]);
  30.    
  31. puts("Z tekstowego:");
  32. FILE *plik_tr=fopen(ftextname,"r");
  33.     for(i=0;i<5;i++)
  34.     fprintf(plik_tr,"%f",tab[i]);
  35. fclose(plik_tr);
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement