Advertisement
xxeell

bin_files

Feb 26th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. void init(FILE* f)
  9. {
  10.     srand(time(0));
  11.     int cnt = 10;
  12.     int n = 2;
  13.     int* ar = new int[cnt];
  14.     for(int i = 0; i < cnt; i++) ar[i] = rand() % 100;
  15.  
  16.     fwrite(&cnt, sizeof(int), 1, f);
  17.     fwrite(ar, sizeof(int), cnt, f);
  18.     fwrite(&n, sizeof(int), 1, f);
  19.  
  20.     for(int i = 0; i < cnt; i++) cout << ar[i] << " ";  cout << "\n";
  21.  
  22.     delete[] ar;
  23. }
  24.  
  25. int main()
  26. {
  27.     FILE* tf = fopen("input.txt", "wb");
  28.     init(tf);
  29.     fclose(tf);
  30.     tf = fopen("input.txt", "rb");
  31.  
  32.     int cnt;
  33.     int n;
  34.     int* ar;
  35.  
  36.     fread(&cnt, sizeof(int), 1, tf);
  37.     ar = new int[cnt];
  38.     fread(ar, sizeof(int), cnt, tf);
  39.     fread(&n, sizeof(int), 1, tf);
  40.  
  41.     for(int i = 0; i < cnt; i++) if(ar[i] % n) cout << ar[i] << " ";
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement