0

我正在使用 C 并且在运行程序时收到此错误。当我输入字符“e”关闭程序时出现错误。请帮我!!!谢谢。:)

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;
 }
4

1 回答 1

2

scanf("%s", &wanted);应该改为scanf("%c", &wanted);

格式字符串%s表示 to 的参数scanf将是一个 char 数组。你有一个字符,所以需要使用%c

于 2012-12-10T22:45:46.230 回答