Question: Need help with C++ code please User enter command line argument that calls the prog and a text file such as > progname fileA I

Need help with C++ code please

User enter command line argument that calls the prog and a text file such as > progname fileA I can get the code to open the file but I am having trouble reading in the contents of the file which I need to parse the contents of later for math operations (decoding an encryption).

My code:

#include #include #include #include #include #include using namespace std; #define MAX 1000 #define S 100

main(int argc, char *argv[]) { int i = 0; int j = 0; int k = 0; char x[MAX], y[MAX], a[MAX], b[MAX]; ifstream inFile; ofstream outFile;

inFile.open(argv[1]); if (inFile.is_open()) { while (!inFile.eof()) { inFile.getline(x, MAX, ' '); inFile.getline(y, MAX, ' ');

} //test for reading in for (int d = 0; d < MAX; d++) { cout << x[d] << " "; d++; } cout << " "; } else { cout << "Unable to open file." << endl; return -1; } inFile.close();

//Parse first line into an array stringstream ssin(x); while (ssin.good() && i < S) { ssin >> a[i]; ++i; } // test cout << i << endl;

//Parse second line into an array stringstream tsin(y); while (ssin.good() && j < S) { tsin >> b[j]; ++j; } //test cout << j << endl; //test for (int c = 0; c < i; c++) { cout << a[c] << " "; } cout << " " << endl; return 0;

}

fileA contents (Two lines):

pq = 323 d = 107 126 60 213 181 144 60 289 78 143 93 253 298 143 60 191 298 223 191 93 78 223 16 60 78 191 60 250 78 312 16 320 60 144 253 298 60 312 223 253 289 320 60 223 78 69 93 143 164 60 277 60 315 143 16 271 16 60 134 181 266 143 78 223

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!