多次元配列 (文字の多次元配列を出力する) を含む C プログラムを作成して少しレビューしましたが、バグに遭遇しました。
プログラムの私の期待される出力は次のとおりです。
.
.
.
A
.
.
.
.
.
しかし、私が得る出力は次のとおりです。
.
.
A //Not meant to be 'A' but rather a '.'
A
.
.
.
.
.
[0][2] の位置に余分な「A」を追加する方法と、この問題を解決する方法を考えています。
これが私のコードです:
#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] = '.';
}
}
}
ありがとうございます=D