【发布时间】:2019-03-25 02:22:46
【问题描述】:
这是我的代码 [注意:不是完整的代码,只有这些会导致问题]
#define RNC 3
int main(int argc, const char *argv[])
{
char *labyrinth[RNC + 2] = {
"00000",
"01100",
"00101",
"01111",
"00101",
};
char *markedLabyrinth[RNC + 2] = {
"00000",
"00000",
"00000",
"00000",
"00000",
};
printf("Test = %s\n", markedLabyrinth[1]);
printf("Please specific where is the exit point Ex. [ 3 5 ] : ");
scanf("%d %d", &K, &L);
int i, row, column;
markedLabyrinth[1] = (char *)malloc(sizeof(char) * 6);
markedLabyrinth[1][2] = '1';
printf("Test After = %s\n", markedLabyrinth[1]);
}
.
这是我的编译器的输出
Test = 00000
Please specific where is the exit point Ex. [ 3 5 ] : 3 4 // this is my input, [ignore it ^^]
Test After = @q1
如您所见,我尝试将 markLabyrinth[1][2] 分配给 = '1' 并且输出应该是
Test After = 00100
但它给了我
Test After = @q1
请帮我看看这段代码,谢谢
【问题讨论】:
-
@user3121023 你能给我一些建议的修复吗?谢谢
-
@user3121023 你的意思是我必须 malloc 所有标记的Labyrinth[0-4] 和 strcpy 将 char 分配给默认值 [00000],而不是在 { ... } 中分配,对吗?
-
@user3121023 哦,谢谢,我试过了,它似乎可以工作;D +1
标签: c arrays pointers struct char