thespeedracer38

File 4

Feb 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char **argv) {
  7.     system("cls");
  8.     if(argc >= 3){
  9.         const char *input_file = argv[1];
  10.        
  11.         ofstream o_fp;
  12.         ifstream i_fp;
  13.         int split_count = argc - 2;
  14.                
  15.         i_fp.open(input_file, ios::binary);
  16.         i_fp.seekg(0, ios::end);
  17.         int in_size = i_fp.tellg();
  18.         i_fp.seekg(0, ios::beg);
  19.         int limit = in_size / split_count;
  20.         int i = 2;
  21.        
  22.         o_fp.open(argv[i], ios::binary);
  23.         for(int j = 1; j <= in_size; j++){
  24.             if(j % limit == 0){
  25.                 i = i + 1;
  26.                 o_fp.close();
  27.                 o_fp.open(argv[i], ios::binary);
  28.             }
  29.             o_fp.put(i_fp.get());
  30.         }
  31.        
  32.         o_fp.close();
  33.         i_fp.close();
  34.        
  35.         cout <<  split_count << " output file(s) created successfuly!" << endl;
  36.         o_fp.close();
  37.         return 0;
  38.     }
  39.     else {
  40.         cout << "In-sufficient number of arguments" << endl;
  41.         cout << "USAGE: File4.exe in_file1 out_file1 [out_file2 ...]" << endl;
  42.         return 1;
  43.     }
  44. }
Add Comment
Please, Sign In to add comment