for my assignment I have to decrypt a .text message in three separate stages but my program is aborted and the core is dumped every time I try to use my function.
What am I doing wrong? the .txt reads this, just in case this helps.
5
eciuj no ognib 6 nogaw ,yadyaM yadyaM
dnuof sretsaot on ,3 nogaw si siht
nrab ot kcab dedaeh ,ereh ollopA
1 egats sa emit eht kram ,sretsaot eht dnuof oleh
ffo gniwohs 2 egats tiuq !!kcubrats
and the five represents how many sentences there are I believe.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
using namespace std;
string reverse_sentence(string *array)
{
cerr << "1" << endl;
reverse(array, array+5);
cerr << "2" << endl;
cerr << "array = " << array << endl;
}
int main()
{
int amount = 5;
string* array;
array = new string[amount];
ofstream stage2 ("stage2.txt");
fstream myfile;
myfile.open("messages.txt");
while (myfile.good())
{
getline(myfile, array[0], ',');
getline(myfile, array[1], ',');
getline(myfile, array[2], ',');
getline(myfile, array[3], ',');
getline(myfile, array[4]);
}
myfile.close();
reverse_sentence(array);
for (int i = 0; i < 5; ++i)
{
stage2 << array[i];
}
delete [] array;
|
Don't mind all the cerrs. I'm just using them to figure out where in my code it started to bug out.
I don't need anyone to do my homework assignment that I posted for me but what I'm wanting to know is what am I doing wrong? I feel the problem is occuring when I pass a string from my array into the function but I don't really get how to do all of that. If I am doing that correctly however the next thing I have to do is store the reverse order back in the original array, so can someone give me an example of how to store items back into the original array? because that really confuses me.