void shiftString(int ,char stringinput[]);
void createTable(char table[][26]);
int main()
{
char array[26][26]={1}; //initialize array
createTable(array); //function which takes 2-D array and feeds values into it
return 0;
}
void shiftString(int n,char stringinput[])
{
//this function shifts the characters in the string left or right by n.left if n is
negative and vice versa.I have to use this to shuffle the characters 'A' to 'Z'
in each row.
}
void createTable(char table[][26]) //this function creates a 26x26 matrix
{
int n=0;
int count=0;
for (int i=0;i<26;i++) //loop for row of matrix
{
char array1[26]= {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','W','Y','Z'}; //initializing 1-D array
shiftString(n,array1); //moves back every character by n.
for (int j=0;j<26;j++)//this loop equals one row of 2-D array to 1-D array
{
table[i][j]=array1[count];
count++;
}
n--; //everytime moving back of character increases by 1
}
for (int a=0;a<26;a++) //these two loops print out the array
{
for (int b=0;b<26;b++) //26 is the size of rows and columns
{
cout<<table[a][b]<<" ";
}
cout<<endl;
}
}
長さが不明な配列を関数に渡しています。関数は「A」から「Z」の文字を入れています。この関数では、自分で作成した別の関数を使用しています(以前にテストされ、完全に正常に動作します)。次のような配列を印刷しようとしました:
M N O P Q R S T U V X W Y Z ü ¥ R · ô ? ~ ·
h a ¨ ¿ ¤ ^ ¨ ¿ Ì | · w ù p · w ù p ·
o · A B C D E F G H I J K L M N O P Q R S T U V X W
Y Z ü ¥ R · ô ? ~ · h a ¨ ¿ ¤ ^ ¨ ¿
Ì | · w ù p · w ù p · o · A B C D E F G H I J
K L M N O P Q R S T U V X W Y Z ü ¥ R · ô ?
~ · h a ¨ ¿ ¤ ^ ¨ ¿ Ì | · w ù p · w ù p ·
o · A B C D E F G H I J K L M N O P Q R S T U V
何が問題なのですか?配列を正しく初期化していますか?メイン コードで出力しようとしましたが、同じ問題です。