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
有什么问题?我是否正确初始化了数组?我试图在主代码中打印出来,但同样的问题。