2012-12-10 95 views
0

我正在使用C &當我運行我的程序時收到此錯誤。當我輸入字符「e」關閉程序時發生錯誤。請幫幫我!!!謝謝。 :)運行時檢查失敗#02

int main() { 
while (true){ 
    HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 
char wanted; 
int c; 
printf("Enter What You Want...\n"); 
printf("f for flower\n"); 
printf("m for mushroom\n"); 
printf("b for box\n"); 
printf("h for mario\n"); 
printf("e to close\n"); 
scanf("%s", &wanted); 
if (wanted=='f'){ 
/*some codes here*/ 
} 
else if (wanted=='m'){ 
/*some codes here*/ 
    } 
    else if (wanted=='b'){ 
/*some code here*/ 
    } 
    else if (wanted=='h'){ 
/*some codes here*/ 
    } 
    else if (wanted=='e'){ 
     printf("Bye.\n"); 
     break; 
    } 
     else { 
      printf("It Was'n a Possible Input. Try Again...\n"); 
     } 
    } 
    return 0; 
} 

回答

2

scanf("%s", &wanted);應改爲scanf("%c", &wanted);

%s格式字符串表示該參數scanf將是一個字符數組。你有一個字符需要使用%c

相關問題