I wrote the following simple program to print out a given matrix:
#include <stdio.h>
#include <stdlib.h>
char matrix[10][10] = {
{'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', '.', ',', '!', '?'},
{'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', '.', ',', '!', '?'},
{'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', '.', ',', '!', '?'},
{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}
};
void printMatrix(char* matrix, int matrix_size)
{
for (int i = 0; i < matrix_size; i = i + 1)
{
for (int j = 0; j < matrix_size; j = j + 1)
{
printf("%c", matrix[i * matrix_size + j]);
if (j == matrix_size - 1)
printf("\n");
}
}
printf("\n");
}
int main()
{
printMatrix(matrix, 10);
}
The program runs as expected, but my compiler (GNU) gives the following warning:
...warning: passing argument 1 of 'printMatrix' from incompatible pointer type [-Wincompatible-pointer-types]|
...note: expected 'char *' but argument is of type 'char (*)[10]'|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 3 second(s)) ===|
Could you please tell me what I am doing wrong?