I've made a C program that involves multi-dimensional arrays (it prints a multi-dimensional array of characters) to review a little, but I came across a bug.
My expected output of the program is:
.
.
.
A
.
.
.
.
.
However the output I get is:
.
.
A //Not meant to be 'A' but rather a '.'
A
.
.
.
.
.
I am wondering how I get that extra 'A' in position [0][2], and how I can fix this problem.
Here is my code:
#include <stdio.h>
void initArray(char shape[][2]);
main()
{
char shape[2][2];
int i, j;
initArray(shape);
shape[1][0] = 'A';
printf("%c\n%c\n%c\n", shape[0][0], shape[0][1], shape[0][2]);
printf("%c\n%c\n%c\n", shape[1][0], shape[1][1], shape[1][2]);
printf("%c\n%c\n%c\n", shape[2][0], shape[2][1], shape[2][2]);
getchar();
}
void initArray(char shape[][2])
{
int i, j;
for(i = 0; i < 3; i ++)
{
for(j = 0; j < 3; j++)
{
shape[i][j] = '.';
}
}
}
Thank you very much =D