我已经编写了 Hangman 的第一个版本。游戏将在稍后完成,届时这部分代码将起作用。
代码:
#include <stdio.h>
#include <conio.h>
int main()
{
char word[]={"name"};
char word0[]={"----"};
char lett;
int i;
int c;
int e=0;
while(e<12)
{
gotoxy(2,2);
printf("\n%s\n",word0);
scanf("%c",&lett);
for(i=0,c=0;i<4;i++)
{
if(lett==word[i])
{
word0[i]=word[i];
c++;
}
}
printf("%d",c);
if(c==0)
{
e++;
printf("%d",e);
}
}
printf("You lose");
getchar();
}
程序在我犯 12 个错误之前结束,并在每个周期打印两个值(不是 1,它应该这样做),这与实际错误数不一致。为什么?
最佳答案
第二个“周期”,如您所说,是读取换行符。尝试将你的 scanf 更改为:
scanf("%c\n",&lett);
关于c - 刽子手游戏的简化(且不完整)版本中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21240988/