Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void zapisz(float tab[],char *fbinname, char *ftextname)
- {
- int i;
- FILE *plik_b=fopen(fbinname,"wb");
- fwrite(tab,5,sizeof(float),plik_b);
- fclose(plik_b);
- FILE *plik_t=fopen(ftextname,"w");
- for(i=0;i<5;i++){
- fscanf(plik_t,"%f",&tab[i]);
- }
- }
- int main(void){
- float tab[5]={1.0,2.0,3.2,4.4,5.5};
- float tab2[5];
- char fbinname[10]="plik.bin";
- char ftextname[10]="plik.txt";
- int i;
- zapisz(tab, fbinname,ftextname);
- FILE *plik_br=fopen(fbinname,"rb");
- fread(tab2,5,sizeof(float),plik_br);
- fclose(plik_br);
- puts("Z binarnego:");
- for(i=0;i<5;i++)
- printf("%f\n",tab2[i]);
- puts("Z tekstowego:");
- FILE *plik_tr=fopen(ftextname,"r");
- for(i=0;i<5;i++)
- fprintf(plik_tr,"%f",tab[i]);
- fclose(plik_tr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement