#include <stdio.h> int main() { int select = 1;//进入循环的条件 while (select != 0) { /*控制台窗口打印菜单选项*/ printf("--Menu--\n"); printf("--sell--1\n"); printf("--buy--2\n"); printf("--showproduct--3\n"); printf("--exit--0\n"); scanf_s("%d",select,2); switch (select) { case 1:printf("you are buying something into store\n"); break; case 2:printf("you are selling to consumer\n"); break; case 3:printf("checking the store\n"); break; case 0:printf("exit\n"); break; default:printf("you put a wrong selection\n"); break; } } system("pause"); }
为什么在控制台窗口输入2之后程序就报出异常中断了呢?
下面贴出两张提示:
解决方案
15
注意sacnf_s的参数
scanf_s(“%d”,select,2); –> scanf_s(“%d”,&select,2);
scanf_s(“%d”,select,2); –> scanf_s(“%d”,&select,2);
5
scanf_s(“%d”,&select,2);