1
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
的問題是什麼我是正確初始化數組我試圖在主代碼中打印出來,但同樣的問題。
另一件事,是不是默認的數組傳遞引用? – User14229754
有沒有原因你不使用'std :: vector'? – moooeeeep