簡單代碼 報(bào)錯 溢出 (本人小白一個)
Run-Time Check Failure #2 - Stack around the variable 'b' was corrupted.
#include <stdio.h>
#define CLEARBUFF scanf("%[^\n]%c")
int main()
{
int a = 0;
int b = 0;
char c = '0';
int d = 0;
printf("請輸入 一個數(shù)字");
scanf_s("%d",&a);
CLEARBUFF;
printf("請?jiān)谳斎?一個數(shù)字:");
scanf_s("%d",&b);
CLEARBUFF;
printf("請輸入符號:");
scanf_s("%s",&c,10);
CLEARBUFF;
switch (c)
{
case '/':
d = a / b;
break;
case '+':
d = a + b;
break;
case '-':
d = a - b;
break;
case '*':
d = a * b;
break;
default:
printf("輸入字符錯誤\r\n");
break;
}
printf("結(jié)果:%d",d);
}