c++ - 奇怪的符号、文本和实际字符在数组中消失/改变

标签 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

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

最佳答案

您已将数组的大小定义为 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 的范围内(含)。

关于c++ - 奇怪的符号、文本和实际字符在数组中消失/改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9204632/

相关文章:

c++ - 在 OpenCV 中创建矩阵后调整其大小

MySQL LOWER() 函数对于 º 字符不是多字节安全的?

c - 如何将unicode转换为符号C

c++ - 条件默认构造函数可以在 GCC 中编译,但不能在 MSVC 中编译

c++ - CascadeClassifier 检测的错误参数

php - 引用 - 这个错误在 PHP 中意味着什么?

java - 如何在 fedora 中 mvndebug

c# - <??> 符号在 C#.NET 中意味着什么?

c++ - 使用特定库的函数

iOS:如何调试 "message sent to deallocated instance"