Advertisement
Patresss

Untitled

Sep 2nd, 2014
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 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.     fprintf(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. float tab3[5];
  20. char fbinname[10]="plik.bin";
  21. char ftextname[10]="plik.txt";
  22. int i;
  23. zapisz(tab, fbinname,ftextname);
  24.  
  25. FILE *plik_br=fopen(fbinname,"rb");
  26. fread(tab2,5,sizeof(float),plik_br);
  27. fclose(plik_br);
  28. puts("Z binarnego:");
  29. for(i=0;i<5;i++)
  30.     printf("%f\n",tab2[i]);
  31.  
  32. puts("Z tekstowego:");
  33. FILE *plik_tr=fopen(ftextname,"r");
  34.     for(i=0;i<5;i++){
  35.     fscanf(plik_tr,"%f",tab3[i]);
  36.     printf("%f\n",tab3[i]);}
  37. fclose(plik_tr);
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement