07 May 2009

To Divid The Huge File.cpp

If we tried to open a 2.3 Gigabyte text file, error message will apear telling you "Notpad can't open the file because it is very huge, try to use a different text editor".
Thus, we will do a program to divid the huge file into 30 parts nearly each of size 76 megabyte nearly and each has 10,000,000 words nearly.
so 10,000,000*30=300,000,000 words. 76*30=2280 megabyte=2.3gigabyte nearly.
-------------------------------------------------------------------------------
// program to divid the whole 2.3 gigabyte  file to 36 parts
//0
#include <iostream>
#include <fstream>
#include <string>

//1
using namespace std;

//2
int main ()
{
    // reading IN file
    ifstream IN;
    IN.open("IN.txt");
    
    // defintions
    char no[] = {'a', 'b', 'c', 'd', 'e'};
    char no1[] = { '1', '2', '3', '4', '5', '6'};
    string name1 = "Part";
    string name;
   
    while (! IN.eof() )
    {
  
   // names of the output files
   for (int i=0; i < 5; i++)
       for (int j=0; j< 6; j++)
       {
    name = name1 + ' ' + no[i] + '_' +  no1[j] + ".txt";
    string s;
    IN >> s;
   // ofstream OUT;
    ofstream OUT;
    OUT.open(name.c_str());
   
    for ( int l=1; l<=10000000; l++)
    {OUT << s << endl;
     IN >> s;}
   
    }
           }
   
    system("pause");
return 0;
    }