Haiku Scholarship
#2
Reminds me of a C++ program I wrote.
I made all of its comments haiku for some reason.
Code:
#include <iostream> #include <fstream> #include <vector> #include "..\Combinator\convtime.h" #define BRATE 616628 using namespace std; int main(int argc, char* argv[]) { cout<<"Text file splitter v. 0.92, 2-26-2012" <<endl; if (argc < 2) // Function takes 2 args { cout<<"Usage:" <<endl; // Otherwise, explains itself cout<<"txtsplit [File Name] [# Strings Per File]" <<endl; cout<<"txtsplit EXAMPLE.TXT 1000000" <<endl; cout<<"Splits EXAMPLE.TXT into files containing up to 1000000 strings each" <<endl; return 0; // Please come back later } ifstream file (argv[1], ios::ate); // Open the target if (!file.is_open()) { // Make sure it really exists cout<<"File not found: " <<argv[1] <<endl; // Elusive, like wind return 1; } cout<<"File " <<argv[1] <<" opened" <<endl; cout<<file.tellg() <<" bytes" <<endl; cout<<"This will take about " <<convtime((file.tellg()) / BRATE) <<endl; file.seekg(0, ios::beg); cout<<"Press Enter when ready" <<endl; // This tells the user cin.get(); // Proceed now, or chicken out? vector<string> readfile; // This vector will read cout<<"Splitting..." <<endl; char ebuf[8]; string str, buffer, ofile, ifile = (argv[1]); // 4 strings: all just names unsigned int i = 0; // Introduce the file counter while (file.good()) // Check for end of file { while ( ((readfile.size()) < (atoi(argv[2]))) // Vector is not full, && (file.good())) { // And the file has not ended, file>>str; // Take a string from it readfile.push_back(str);} // Insert in vector ofile = (_itoa (i,ebuf,10)); // Change the string to a number ofile += "_" + ifile; // Append the filename ofstream outputfile (ofile, ios::trunc); // Create this new file for (unsigned j=0; j < readfile.size(); j++) { // For each string in the vector, outputfile<<(readfile.at(j)) + "\n"; // Write to the output } outputfile.close(); // Close the outputfile readfile.clear(); // Now empty the read buffer i++; // Increment the count } // This loop has ended file.close(); // It is time to stop reading return 0; // The split is complete }
Thanks given by:


Messages In This Thread
Haiku Scholarship - by Lantry - 11 Sep 12, 06:56PM
RE: Haiku Scholarship - by V-Man - 11 Sep 12, 07:32PM
RE: Haiku Scholarship - by Frogulis - 12 Sep 12, 11:37AM
RE: Haiku Scholarship - by MykeGregory - 16 Sep 12, 09:59PM
RE: Haiku Scholarship - by Oracle - 16 Sep 12, 10:49PM
RE: Haiku Scholarship - by Waffles - 17 Sep 12, 12:11AM
RE: Haiku Scholarship - by Oracle - 17 Sep 12, 12:13AM
RE: Haiku Scholarship - by MykeGregory - 17 Sep 12, 08:25AM
RE: Haiku Scholarship - by V-Man - 17 Sep 12, 08:45AM
RE: Haiku Scholarship - by Orynge - 17 Sep 12, 08:49AM
RE: Haiku Scholarship - by V-Man - 17 Sep 12, 09:48AM
RE: Haiku Scholarship - by Oracle - 17 Sep 12, 03:01PM
RE: Haiku Scholarship - by V-Man - 17 Sep 12, 03:17PM
RE: Haiku Scholarship - by Oracle - 17 Sep 12, 03:37PM
RE: Haiku Scholarship - by Ronald_Reagan - 17 Sep 12, 03:54PM
RE: Haiku Scholarship - by V-Man - 17 Sep 12, 04:12PM
RE: Haiku Scholarship - by Bullpup - 18 Sep 12, 07:11PM
RE: Haiku Scholarship - by V-Man - 18 Sep 12, 07:29PM