Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- void random(float arr[],int n);
- void print(float arr[],int n);
- int text_size();
- int binary_size();
- void file_size_print();
- int main()
- {
- float tab[100];
- random(tab,100);
- print(tab,100);
- file_size_print();
- return 0;
- }
- void random(float arr[],int n)
- {
- srand(time(NULL));
- int i=0;
- for (i; i<n; i++) arr[i]=rand()%100;
- }
- void print(float arr[],int n)
- {
- FILE * fp = fopen("wynik_binarny.bin", "wb");
- FILE * fp1 = fopen("wynik_tekstowy.txt", "w");
- int i=0;
- fwrite(arr,sizeof(float),100,fp);
- for (i; i<n; i++)
- {
- printf("[%.1f]",arr[i]);
- fprintf (fp1, "%.1f\n",arr[i]);
- }
- fclose(fp);
- fclose(fp1);
- FILE * _fp = fopen("wynik_binarny.bin", "rb");
- FILE * _fp1 = fopen("wynik_tekstowy.txt", "r");
- fread(arr,sizeof(float),100,_fp);
- for(i=0; i<100; i++)printf("[%.1f]",arr[i]);
- for(i=0; i<100; i++)
- {
- fscanf(_fp1,"%.1f\n",arr[i]);
- printf("[%.1f]",arr[i]);
- }
- fclose(_fp);
- fclose(_fp1);
- }
- int text_size()
- {
- FILE *fp = fopen("wynik_tekstowy.txt", "r");
- fseek(fp, 0, SEEK_END);
- int lengthOfFile = ftell(fp);
- fclose(fp);
- free(fp);
- return lengthOfFile;
- }
- int binary_size()
- {
- FILE *fp = fopen("wynik_binarny.bin", "rb");
- fseek(fp, 0, SEEK_END);
- int lengthOfFile = ftell(fp);
- fclose(fp);
- free(fp);
- return lengthOfFile;
- }
- void file_size_print()
- {
- int size_txt=text_size();
- int size_bin=binary_size();
- printf("\n\nRozmiar 1 %d\nRozmiar 2 %d\n",size_txt,size_bin);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement