Run-Time Check Failure #2 - Stack around the variable 'e' was corrupted.我是用的C语言,我的源代码如下:#includeint main(){\x05short/*short如改成int就不会stack was corrupted了*/ a=0,b=0,c=0,d=0,e=0;\x05puts("Input a number that end

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 08:07:52
Run-Time Check Failure #2 - Stack around the variable 'e' was corrupted.我是用的C语言,我的源代码如下:#includeint main(){\x05short/*short如改成int就不会stack was corrupted了*/ a=0,b=0,c=0,d=0,e=0;\x05puts(

Run-Time Check Failure #2 - Stack around the variable 'e' was corrupted.我是用的C语言,我的源代码如下:#includeint main(){\x05short/*short如改成int就不会stack was corrupted了*/ a=0,b=0,c=0,d=0,e=0;\x05puts("Input a number that end
Run-Time Check Failure #2 - Stack around the variable 'e' was corrupted.
我是用的C语言,我的源代码如下:
#include
int main()
{
\x05short/*short如改成int就不会stack was corrupted了*/ a=0,b=0,c=0,d=0,e=0;
\x05puts("Input a number that ends with a '.'");
\x05scanf("%1d%1d%1d%1d%1d",&a,&b,&c,&d,&e);
\x05if(e)
\x05{
\x05\x05puts("five digits");
\x05\x05printf("%d %d %d %d %d\n",a,b,c,d,e);
\x05\x05printf("%d%d%d%d%d\n",e,d,c,b,a);
\x05}
\x05else if(d)
\x05{
\x05\x05puts("four digits");
\x05\x05printf("%d %d %d %d\n",a,b,c,d);
\x05\x05printf("%d%d%d%d\n",d,c,b,a);
\x05}
\x05else if(c)
\x05{
\x05\x05puts("three digits");
\x05\x05printf("%d %d %d\n",a,b,c);
\x05\x05printf("%d%d%d\n",c,b,a);
\x05}
\x05else if(b)
\x05{
\x05\x05puts("two digits");
\x05\x05printf("%d %d\n",a,b);
\x05\x05printf("%d%d\n",b,a);
\x05}
\x05else if(a)
\x05{
\x05\x05puts("one digit");
\x05\x05printf("%d\n",a);
\x05\x05printf("%d\n",a);
\x05}
\x05else
\x05{
\x05\x05puts("the number is zero");
\x05\x05printf("0\n");
\x05\x05printf("0\n");
\x05}
\x05return 0;
}
结果出现了题目中的错误提示,如果short改成int,则一切正常,

Run-Time Check Failure #2 - Stack around the variable 'e' was corrupted.我是用的C语言,我的源代码如下:#includeint main(){\x05short/*short如改成int就不会stack was corrupted了*/ a=0,b=0,c=0,d=0,e=0;\x05puts("Input a number that end
scanf( "%d",...) 需要你传一个int大小的地址
short 是2字节,int是4字节,你给需要4字节的,传一个2字节,自然就溢出了,好比,1L的瓶子,你灌了2L的水,是不是就溢出了?