簡體   English   中英

C程序:多字猜謎游戲轉換錯誤

[英]C program: multi-word guessing game conversion error

我剛剛編寫了一個相當大的游戲塊,它運行得很好但是將猜測詞轉換成星號,並且有空格的空間。 例如,如果單詞是“雞塊”,它應該像“****** *******”,但它出來“************** “既然代碼要發布到這里很長很遠,我知道這就是我出錯的路線,但我還是想不通一下。

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

任何幫助或推動正確的方向將不勝感激。

// 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] = '*';
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM