hangman code: line 113-125 https://pastebin.com/r1B8rkD1
一切都很好,除了当我包含这行代码时:
//Verify mask if all is filled up.
int sea;
gameover=1;
// for(sea=0;sea<length;sea++)
{
if(!mask[sea])
{
gameover = 1;
break;
}
}
可能是什么问题?当我将其包含在我的代码中时,它没有显示任何结果。非常感谢您的帮助。谢谢
最佳答案
此时 - if(!mask[sea])
,变量sea
未分配。您正在使用 sea
的值作为 mask
的偏移量。这会导致UB 。
for
您注释掉的语句首先分配整数 0
至sea
使用赋值运算符=
。假设mask
是一个数组,您正在使用 sea
的值跳转到 if
中数组的特定元素声明。
现在,sea
未分配,它可能是任何东西(甚至是负数)。因此,您尝试使用未知索引访问数组中的某些元素。这就好像你知道你的 friend 住在哪条街上,但你不知道门牌号。
HTH
关于c - C语言代码出现问题: No display when including a specific block of code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59458305/