#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "stdlib.h"
using namespace std;
void flush_left ( ofstream &out_file, int width,
vector <string> v1)
{
int new_line = 0;
int line_size =0;
for ( int i =0; i< width+4; i++)
{
out_file << "-";
}
out_file << endl;
for ( int i = 0; i < v1.size() ;i++)
{
if ( new_line == 0)
{
line_size = line_size + v1[i].size()+1;
out_file << "| " << v1[i];
new_line = 1;
cout << "1" << v1[i] << endl;
}
else
{
if ( line_size + v1[i].size()+1 <= width)
{
line_size = line_size + v1[i].size()+1;
out_file << " " << v1[i];
new_line = 1;
cout << "2" << v1[i] << endl;
}
else
{
for ( int j = line_size; j < width+4; j++)
{
out_file << " ";
}
out_file << "|" << endl;
out_file << "| " << v1[i];
line_size = v1[i].size()+1;
new_line = 1;
cout << "3" << v1[i] << endl;
}
}
}
for ( int i=0; i< width-line_size; i++)
{
out_file << " ";
}
out_file << "|";
out_file << endl;
for ( int i =0; i< width+4; i++)
{
out_file << "-";
}
}
void flush_right ( ifstream file, int num )
{
}
void full_justify ( ifstream file, int num )
{
}
int main( int argc, char* argv[])
{
ifstream file(argv[1]);
if ( !file )
{
cerr << "Can't open " << argv[1] << " to read. \n";
return 1;
}
string words;
vector <string> vec_words;
while ( file >> words )
{
vec_words.push_back(words);
}
ofstream out_file( argv[2]);
if ( !out_file)
{
cerr << " Can't open " << argv[2] << " to write.\n";
return 1;
}
int number = atoi(argv[3]);
string name = argv[4];
if ( name == "flush_left" )
flush_left ( out_file, number, vec_words );
}