奇怪的符号,文本和实际字符在数组中消失/变化

时间:2012-02-09 02:31:55

标签: c++ debugging symbols

Here is a photo of when I debug my code in Visual C++, the highlighted things are the abnormal parts, where I circled nothing is where dashes are supposed to be.

好吧,正如你在上面看到的那样,有些奇怪的东西出现而不是通常的破折号。

这是我的代码,因为它很长:http://tinypaste.com/7a115ecc

如果您想知道它是生命游戏,可以选择使用更改的规则。

2 个答案:

答案 0 :(得分:3)

您已将数组定义为大小为10(即,它们具有从0到9的元素),但您的循环运行超过11个元素:

char world[10] [10];
for (int m = 0; m < 11; m++)
 {
     for (int n = 0; n < 11; n++)
     {
         neighbors = 0;
         //Begin counting number of neighbors:
         if(world[m-1][n-1] == '+')neighbors++;
         . . .

然后,当mn为0时,您正在访问world[-1][-1]

您需要确保指数保持在0 - 9(包括0和9)的范围内。

答案 1 :(得分:0)

你的内存中可能有垃圾。