好吧,我不知道为什么会发生这种情况。
这是我正在处理的函数。
while (map[x] && height <= box.size)
{
width = 0;
while (width <= box.size && height <= box.size)
{
if (map[x] == '.' || map[x] == 'x')
{
main_box[x] = 'x';
n_of_fill++;
width++;
}
if (map[x] == 'o')
break;
x++;
}
//To move a line down and start at the beginning of that line
x = x + true_y + 1 - width;
box.size = width;
height++;
}
printf("3 \n\n%s\n\n%s\n\n%sfill = %i, width = %i, height = %i\n\n", main_box, map, tempmap, n_of_fill, width, height);
我传递了一个 map ,声明了另外 2 个 map (tempmap 和 main_box)。一开始我将 tempmap 和 main_box 设置为 map,该函数按照其指示执行操作,(甚至很难,但它并不正确)...但现在在代码末尾,当我打印所有 map 时,所有 map 是一样的吗??
当在循环中时,我只更改 map ,并且没有将 main_box 或 tempmap 设置为 map ,那么为什么它们在函数末尾都相同?!!
这是完整的代码(要小心很长且写得很糟糕的代码) http://pastebin.com/SdnJYPqP
任何帮助都会很棒,如果我是一个彻头彻尾的白痴,我很抱歉......
最佳答案
我真是太傻了。 main_box
和 tempmap
是指向 map
的指针,所以当我更改 map
并调用所有其他函数时,它调用的是相同的事物。谢谢您的帮助!归功于巴马尔
关于c - 仅分配一次时,3 个字符串获得相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36654492/