Question: Need help with C++ I am having trouble with converting decimals into ASCII characters. (For reference, this code takes command arg that reads in a
Need help with C++
I am having trouble with converting decimals into ASCII characters. (For reference, this code takes command arg that reads in a file such as >progname fileA)
My code:
#include
main(int argc, char *argv[]) { int i = 0; int j = 0; int k = 0; long long m = 0; long long n = 0; long long p = 0; long long r = 1; string a[MAX], b[MAX]; ifstream inFile; ofstream outFile; string line1, line2;
cout << "CS251 - Lab 3 - Melissa Shanks" << endl;
inFile.open(argv[1]); if (inFile.is_open()) { getline(inFile,line1); getline(inFile,line2);
//test for reading in cout << line1 << endl; cout << line2 << endl; } else { cout << "Unable to open file." << endl; return -1; } inFile.close();
//Parse first line into an array stringstream ssin(line1); while (ssin.good() && i < S) { ssin >> a[i]; ++i; }
//Parse second line into an array stringstream tsin(line2); while (tsin.good() && j < S) { tsin >> b[j]; ++j; }
for (int c = 0; c < j; c++) { //Convert string into long long //Base m = stoll(b[c]); //Exponent n = stoll(a[5]); //Modulo p = stoll(a[2]);
//Calculate base m %= p;
//Calculate residue while(n > 0) { if (n&1) { r = r * m % p; } m = m* m%p; n>>=1; } //Display decimal as ASCII character cout << static_cast
return 0; } Contents of fileA (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
Get step-by-step solutions from verified subject matter experts
