I was in needing of printing a Vigenere square inside a console window for a personal project but I'm experiencing some problems with the print function since it sneaks inside other classes' memory and prints out strings coming from them.
For those who don't know what is a Vigenere square, here's a picture
Here's my code:
static void square() {
string cipher[27];
cipher[0] = " | 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";
for (int i = 0; i < 26; i++) {
string tmp = (char)(i + 'A') + " |";
for (int j = 0; j < 26; j++) {
tmp += " " + (char)(((j + i) % 26) + 'A');
}
cipher[i + 1] = tmp;
}
for (int i = 0; i < 27; i++) cout << cipher[i] << endl;
}
My approach consists in creating each string one by one using a for cycle which incrememts the row's letter ascii value and another for for each of the coloumns shifted by 1. This is the weird output:
I'm running this code alone but it steals the string "Invalid Option! Press any key to dismiss."
from a class that I previously used to create the menu. I think it's someway how accessing parts of the memory reserved to that class.
What am I doing Wrong?