簡(jiǎn)單代碼 報(bào)錯(cuò) 溢出 (本人小白一個(gè))
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("請(qǐng)輸入 一個(gè)數(shù)字");
scanf_s("%d",&a);
CLEARBUFF;
printf("請(qǐng)?jiān)谳斎?一個(gè)數(shù)字:");
scanf_s("%d",&b);
CLEARBUFF;
printf("請(qǐng)輸入符號(hào):");
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("輸入字符錯(cuò)誤\r\n");
break;
}
printf("結(jié)果:%d",d);
}