I am really noob in programming, I know xD
I just started to learn, and this is my task - to make a simple text decoder.
So here it is:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string alp[26] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
int key;
int let;
string mid;
int i;
int g;
int m;
cout << ("Enter key:");
cin >> key;
cout << ("Enter number of letters:");
cin >> let;
vector<string> out;
for(i = 1; i <= let; i++)
{
cout << ("Enter word by letters:") << endl;
cin >> mid;
for(g = 0; g <= 26; g++)
{
if(mid == alp[g]){
string sum;
int sumlet = g + key;
if(sumlet >= 26){
int c = 26 - sumlet;
sumlet = c * -1;
sum = alp[sumlet];
out.push_back(sum);
}else if(sumlet << 0){
int c = sumlet * -1;
sumlet = 26 - c;
sum = alp[sumlet];
out.push_back(sum);
}else
{sum = alp[sumlet];
out.push_back(sum);
}
}else{
}
}
}
cout << "Your text is: ";
for(m = 0; m <= let; m++ ){
cout << out[m];
}
}
And it's returning me this after i enter all the letters:
Terminated due to signal: ABORT TRAP (6)
decoder(1367,0x7fffd9b9f3c0) malloc: * mach_vm_map(size=140734634131456) failed (error code=3) * error: can't allocate region *** set a breakpoint in malloc_error_break to debug libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
What's the problem? Help please.
Aucun commentaire:
Enregistrer un commentaire