Andrii Kovach
Andrii Kovach

Reputation: 1

why have i bus error 10, when I put cout<<""<<endl; out of my code

I have written a code, but there’s one Problem. When I put cout<<""<<endl; out, I have Bus error: 10. How can I solve this Problem. This is my code:

#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <cstdlib>
#include <cstring>
#include <assert.h>
#include <ctime>
#include <sstream>
#include <iostream>
#include <iomanip>
using namespace std;
char* rotate(char const* a, int b)
{
    char* r;
    for (int i = 0; i < int(strlen(a)); i++) {
        if (i >= int(strlen(a)) - b) {
            r[i] = a[i - int(int(strlen(a)) - b)];
        }
        else if (i + b < 0) {
            r[i] = a[int(strlen(a) + b)];
        }
        else {
            r[i] = a[i + b];
        }
    }
    r[int(strlen(a))] = '\0';
    return r;
}
char* Crypt(char* Input, bool Encrypt, int InitialRotation, int Rotation)
{
    char const* Table;
    try {
        Table = new char[size_t(strlen(Table))];
    }
    catch (...) {
        throw "No Memory";
    };
    char* a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    try {
        a = new char[size_t(strlen(a))];
    }
    catch (...) {
        throw "No Memory";
    };
    char* ActualTable;
    try {
        ActualTable = new char[size_t(strlen(ActualTable))];
    }
    catch (...) {
        throw "No Memory";
    };
    int Offset = InitialRotation;
    char* Result;
    try {
        Result = new char[size_t(strlen(Result))];
    }
    catch (...) {
        throw "No Memory";
    };
    int b;
    Table = "JPGVOUMFYQBENHZRDKASXLICTW";
    a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (int i = 0; i < int(strlen(Input)); i++) {
        for (int c = 0; i < int(strlen(a)); c++) {
            if (a[c] == Input[i]) {
                b = c;
                break;
            }
        }
        cout << "" << endl;
        ActualTable = rotate(Table, Offset);
        Result[i] = rotate(Table, Offset)[b];
        Offset = Offset + Rotation;
    }
    return Result;
}
int main()
{
    char* A = "ZZZZ";
    cout << Crypt(A, 1, 1, 4) << endl;

    return 0;
}

Upvotes: 0

Views: 172

Answers (0)

Related Questions