运行时检查失败#02

时间:2012-12-10 22:43:18

标签: c

我正在和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;
 }

1 个答案:

答案 0 :(得分:2)

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

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