我必須創建一個函數來寫出字母表中可用的字母。例如,用戶類型a
和功能輸出將是bcdefgh...
函數的輸出值與循環中的printf值不匹配
如果我在循環中使用printf
一切都沒問題。但是,如果我將該字母寫入數組,然後我想打印出數組,則會在輸出中得到完整的字母表。
void getAvailableLetters(const char lettersGuessed[],char availableLetters[]){
char abeceda[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','q','p','r','s','t','v','u','w','x','y','z'};
printf("Available letters: ");
int x=0;
int i;
for(i=0 ; i<strlen(abeceda); i++){
for(int j=0 ; j<strlen(lettersGuessed); j++){
if(abeceda[i] == lettersGuessed[j]){
x=1;
}
}
if(x==0){
availableLetters[i]=abeceda[i];
//printf("%c",abeceda[i]);
}
x=0;
}
printf("%s",availableLetters);}
如果我使用printf
在註釋輸出還是不錯的,但是從陣列availableLetters
輸出包含完整的字母表。
'','z'};' - >','z',0};' – BLUEPIXY 2015-04-04 22:19:04
翻譯BLUPIXY的評論 - 如果你打算使用'abededa'字符數組作爲'string',你必須'null-終止'數組就像一個'字符串'.. – 2015-04-04 22:35:47