/* main.cpp for xref.exe a program to cross-reference a CSV file against three data files and use MS Excel automation to create a new .xls file with the results.Microsoft Excel must be installed on the machine on which this program is run in order to output the results properly. How to use: this program expects one parameter, the number in the filename of the csv file. If the filename is FileExchange_Response_12345.csv, start the program with "xref.exe 12345"*/// the class used for automation//#include "/home/silly/work/rentacoder.com/709970/myproject/XLEzAutomation.h"#include <iostream>#include <fstream>#include <string>using namespace std;// prototype for check_dat functionvoid check_dat ( ifstream& );// declare csv varsstring line_CSV, columnD_CSV, columnA_CSV;int main ( ){ const char csvfile[] = "data/FileExchange_Response_2221585.csv", dvdfile[] = "data/DVDC.dat", vidfile[] = "data/VideoC.dat", gamefile[] = "data/GamesC.dat";; // the input files ifstream inFile_CSV ( csvfile ), inFile_DVD ( dvdfile ), inFile_Vid ( vidfile ), inFile_Game ( gamefile ); // check if they opened if ( !inFile_CSV || !inFile_DVD || !inFile_Vid || !inFile_Game ) { cerr << "one or more input files did not open\n"; exit ( -1 ); } inFile_DVD.close ( ); inFile_Vid.close ( ); inFile_Game.close ( ); // initialize the csv vars line_CSV = columnD_CSV = columnA_CSV = ""; // do a full run while ( !inFile_CSV.eof ( ) ) { // read one line from 'inFile_CSV' and store it in 'line_CSV' getline ( inFile_CSV, line_CSV ); // find "UPC" in 'line_CSV' and store the position of the "U" in 'loc' string::size_type loc = line_CSV.find ( "UPC", 0 ); if ( loc != string::npos ) { // get the value in column D from the CSV columnD_CSV = line_CSV.substr ( ( loc + 4 ), 12 ); // if there is a comma, the value does not represent a 12-digit number if ( columnD_CSV.find ( ",", 0 ) == string::npos ) { inFile_DVD.open ( dvdfile ); check_dat ( inFile_DVD ); inFile_Vid.open ( vidfile ); check_dat ( inFile_Vid ); inFile_Game.open ( gamefile ); check_dat ( inFile_Game ); } } } // end while ( !inFile_CSV.eof ( ) ) inFile_CSV.close ( ); return 0;} // end main()void check_dat ( ifstream &dat ){ // declare dat vars string line_dat, column7_dat, column1_dat, column3_dat; // initialize them line_dat = column7_dat = column1_dat = column3_dat = ""; while ( !dat.eof ( ) ) { // read one line from 'inFile_DVD' and store it in 'line_dat' getline ( dat, line_dat ); // catch the last byte of the dat file (0x1a) and break if ( line_dat.find ( 0x1a, 0 ) != string::npos ) { dat.close ( ); break; } column7_dat = line_dat.substr ( 167, 12 ); if ( columnD_CSV == column7_dat ) { // get the value in column A from the CSV file columnA_CSV = line_CSV.substr ( 0, 12 ); cout << " csvA: " << columnA_CSV; // get the value in column 1 from the dat file column1_dat = line_dat.substr ( 0, 14 ); cout << " dat1: " << column1_dat; // get the value in column 3 from the dat file column3_dat = line_dat.substr ( 91, 25 ); cout << " dvd3: " << column3_dat << "\n"; //break; } } // end while ( !inFile_dat.eof ( ) ) dat.close ( );} // end check_dat