Hey I want to copy an arrow matrix to another matrix and rotate the arrow in it 90 degrees clock wise. I managed to rotate from pointing to 3 to 6 but when I try to rotate it again to 9 it goes back to 3.
I think the problem is that I need to take the whole column first from the end but unsure how to do it
#include <stdio.h>
#include <string.h>
void DisplayArray2D(char arr[][7]);
void RotateArray2D(char arrRotated[][7], char arrOriginal[][7]);
void main() {
char arr[7][7] = {
{ '*',' ',' ',' ',' ',' ',' '},
{ '*','*',' ',' ',' ',' ',' '},
{ '*','*','*',' ',' ',' ',' '},
{ '*','*','*','*','*','*','*'},
{ '*','*','*',' ',' ',' ',' '},
{ '*','*',' ',' ',' ',' ',' '},
{ '*',' ',' ',' ',' ',' ',' '},
};
char arr6[7][7];
char arr9[7][7];
DisplayArray2D(arr);
RotateArray2D(arr6,arr);
DisplayArray2D(arr6);
RotateArray2D(arr9,arr6);
DisplayArray2D(arr9);
}
void DisplayArray2D(char arr[][7]){
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 7; j++)
{
printf("%c",arr[i][j]);
}
printf("\n");
}
}
void RotateArray2D(char arrRotated[][7], char arrOriginal[][7]){
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 7; j++)
{
arrRotated[j][i] = arrOriginal[i][j];
}
}
// DisplayArray2D(arrRotated);
}
Thanks guys, your comments really helped. indeed I was missing the [6-i] in the function in order to rotate the right way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.