Strange output when trying to display an array of characters C++

  arrays, ascii, c++, struct

I’m trying to create a Rotor struct that holds arrays of characters in a specific sequence.

struct Rotor
{
public:

    char assignedRotor[26];

    void setRotor(int rotor)
    {
        switch(rotor)
        {
            case(1):
                for(int i; i < sizeof(rotor1); i++)
                {
                    assignedRotor[i] = rotor1[i];
                }
                break;
            case(2):
                for(int i; i < sizeof(rotor1); i++)
                {
                    assignedRotor[i] = rotor2[i];
                }
                break;
            case(3):
                for(int i; i < sizeof(rotor1); i++)
                {
                    assignedRotor[i] = rotor3[i];
                }
                break;
        };
    }
private:
    char rotor1[26] = {'E', 'K', 'M', 'F', 'L', 'G', 'D', 'Q', 'V', 'Z', 'N', 'T', 'O', 'W', 'Y', 'H', 'X', 'U', 'S', 'P', 'A', 'I', 'B', 'R', 'C', 'J'};
    char rotor2[26] = {'A', 'J', 'D', 'K', 'S', 'I', 'R', 'U', 'X', 'B', 'L', 'H', 'W', 'T', 'M', 'C', 'Q', 'G', 'Z', 'N', 'P', 'Y', 'F', 'V', 'O', 'E'};
    char rotor3[26] = {'B', 'D', 'F', 'H', 'J', 'L', 'C', 'P', 'R', 'T', 'X', 'V', 'Z', 'N', 'Y', 'E', 'I', 'W', 'G', 'A', 'K', 'M', 'U', 'S', 'Q', 'O'};
};

No issues with the first and third rotor configurations. However, when I try to display the second rotor:

int main()
{
    Machine enig;

    for(int i; i < 26; i++)
    {
        cout << enig.rotor2.assignedRotor[i] << endl;
    };

    return 0;

}

I get this as an output:

Output

Source: Windows Questions C++

LEAVE A COMMENT