C程序:多字猜谜游戏转换错误

时间:2015-03-06 23:29:57

标签: c output

我刚刚编写了一个相当大的游戏块,它运行得很好但是将猜测词转换成星号的问题是有空间的空间。 例如,如果单词是“鸡块”,它应该像是一样 “****** *******” 但相反它出来了“**************” 由于这里的代码很长很难发布,我知道这是我出错的路线,但是我还是找不到解决方法。

for(i=0;i<strlen(words);i++){string[i]='*';}

任何帮助或推动正确的方向将不胜感激。

1 个答案:

答案 0 :(得分:0)

// Compute the length of the string ahead of the loop.
// Don't compute it in every run of the loop.
int len = strlen(words);
for ( i = 0; i < len; i++)
{
   if (!isspace(words[i]) )
   {
      words[i] = '*';
   }
}
相关问题