Skip to content

Instantly share code, notes, and snippets.

@sms420
Created July 1, 2009 03:30
Show Gist options
  • Select an option

  • Save sms420/138569 to your computer and use it in GitHub Desktop.

Select an option

Save sms420/138569 to your computer and use it in GitHub Desktop.
/* fedexAPP.cpp
*********************************************************/
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
int main () {
string row_of_data;// temporary string to hold line of data
ifstream inputFile ("in.txt");
ofstream outputFile;
outputFile.open("out.txt");
if (inputFile.is_open() && outputFile)
{
while (! inputFile.eof() )
{
// read line from INPUT.txt & copy to row_of_data
getline (inputFile,row_of_data);
// dynamically alocate enough memory for char array
char *a=new char[row_of_data.size()+1];
// assign zero to the first value in the array
a[row_of_data.size()]=0;
// copy data from row_of_data into char array
memcpy(a,row_of_data.c_str(),row_of_data.size());
/* write to outputFile character, by character, literally */
// (0) invoice date mmddyy
outputFile << a[5] << a[6] << a[7] << a[8]
<< a[3] << a[4] << endl;
// (1.1) shipping date mmddyy
outputFile << "1" << a[16] << a[17] << a[18]
<< a[19] << a[14] << a[15];
// (1.2) client matter
outputFile << a[26] << a[27] << a[28]
<< a[26] << a[27] << a[28]
<< a[29] << a[30] << a[31];
// (1.3) this thing, whatever it is
outputFile << " HMSG 1 ";
// the amount is variable ... we need some saucyness
// the different elements represent tens, hundreds or thousands
if ( a[36] == '.' )
outputFile << a[35] << a[36] << a[37] << a[38];
else if ( a[37] == '.' )
outputFile << a[35] << a[36] << a[37] << a[38] << a[39];
else if ( a[38] == '.' )
outputFile << a[35] << a[36] << a[37] << a[38] << a[39] << a[40];
else
outputFile << a[35] << a[36] << a[37] << a[38] << a[39] << a[40] << a[41];
// (3.1) our fedex number
outputFile << endl << "300001123";
int index = 0; //this is to keep track of elements we are printing
int dot_only_for_invoice_amount = 0; // you don't want to know, really ...
// everything else is variable b/c amount is variable in size
for (int i = 54; i < row_of_data.size(); i++)
{
// (3.3) re-print invoice date ... this was thr tough part
if (index == 9)
{
outputFile << " ";
outputFile << a[5] << a[6] << a[7] << a[8] << a[3] << a[4];
index++;
}
// endline after total invoice amount
// then start line 4
if ( ( a[i] == '.' ) && ( dot_only_for_invoice_amount == 0 ) )
{
dot_only_for_invoice_amount = 1;
outputFile << a[i];
++i;
outputFile << a[i];
++i;
outputFile << a[i];
outputFile << endl;
++i;
outputFile << "4TRACK ID ";
i = i + 3;
outputFile << a[i] << a[i+1] << a[i+2] << a[i+3] << a[i+4] << a[i+5]
<< a[i+6] << a[i+7] << a[i+8] << a[i+9] << a[i+10] << a[i+11]
<< endl << "4DELIVERY TO ";
i = i + 12;
}
//if person and no company
if ( ( ( a[i] == '\"' ) && ( a[i+1] == '\"' ) && ( a[i+2] == '*' ) && ( a[i+3] == '\"' ) )
&& (i > 100))
break;
//if person and company
if ( ( ( a[i] == '\"' ) && ( a[i+1] == '*' ) && ( a[i+2] == '\"' ) )
&& (i > 100))
outputFile << endl << "4";
//if company and no person
if ( ( ( a[i] == '\"' ) && ( a[i+1] == '*' ) && ( a[i+2] == '\"' ) && ( a[i+3] == '\"' ))
&& (i < 100))
outputFile << endl << "4";
// if the machine encounters a comma, or * delete it
if ( ( a[i] == '*' ) || ( a[i] == '\"' ) )
continue;
else
{
outputFile << a[i];
index++;
}
}//closes for loop, we've iterated over one line, woohoo
outputFile << endl << endl; //add endline before next entry
} // closes: while (! inputFile.eof() )
inputFile.close();
outputFile.close();
} // closes: (inputFile.is_open() && outputFile)
return 0;
} //** closes: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment