Stack around the variable 'date' was corrupted.
為什么80%的碼農都做不了架構師?>>> ??
代碼如下:
#include <stdio.h>
#include <Windows.h>
?
// in 64 win7 vs2010...here ? ?have to define a 8s' space.. so defined e00_date.wee
struct e00_date{
unsigned short int year;
unsigned short int month;
unsigned short int day;
//unsigned char tt;
//unsigned short week;
};
typedef struct e00_date e00_date;
void main()
{
e00_date date;
unsigned short int sum=0;
puts("input a date (format: yyyy/mm/dd)");
scanf("%d/%d/%d",&date.year,&date.month,&date.day);
if(date.month>12||date.month<1)
{
puts("please input a viald value");
system("pause");
exit(0);
}
?
sum+=date.day;
switch(date.month)
{case 12: sum+=30;
case 11: sum+=31;
case 10: sum+=30;
case 9: sum+=31;
case 8: sum+=31;
case 7: sum+=30;
case 6: sum+=31;
case 5: sum+=30;
case 4: sum+=31;
case 3: sum+=28;
case 2: sum+=31;
case 1: break;
}
if(((date.month%4==0)&&(date.month%100!=0))||(date.month%400==0))
if(date.month>2)
sum++;
printf("\nthis the %hu days in %4hu/%02hu/%02hu(yyy/mm/dd)",sum,date.year,date.month,date.day); system("pause");
}
#################################################
今天遇到一個錯誤如題,在程序結尾來了這么一下。
解決方法一:
但是在struct e00_date里面在加一個char或者 short。就正常了(struct 注釋的2個變量),添加變量是為了使struct的size大>=8,64位的系統,所以猜想是這里有問題?!但是沒道理啊,其他2,4,6大小的struct都沒問題。。
解決方法二:
網上找,都說是越界了。。然后debug一個一個找,數據都能正確的存到變量里。后面沒辦法了,一個一個的格式化輸入輸出,
scanf那,把%d改成%hu,最終就OK了。還是很納悶。。程序運行到system("pause");最后面了,才報錯,前面都過的去,怎么這里這么就出來了。。(1.這里都沒有訪問數據讀取了。怎么出現錯誤。2.存儲空間數據也是正確存入了,也就是說在short的2個字節范圍內沒有異常數據。它憑什么就被corrupted。就算輸入1998/9/25(0x07ce/0x0009/0x0019)可能會變成(0x000007ce,0x00000009,0x00000019)最多就是把2個字節以外的0丟失嘛。。
?
真心搞不通啊。是不是理解有錯~~求解釋~~~~~
?
轉載于:https://my.oschina.net/singlem1905/blog/82937
總結
以上是生活随笔為你收集整理的Stack around the variable 'date' was corrupted.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 更新系统时跳过某个软件包
- 下一篇: C语言字符串拷贝