Stack around the variable 'date' was corrupted.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
代碼如下:
#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");
}
#################################################
今天遇到一個(gè)錯(cuò)誤如題,在程序結(jié)尾來(lái)了這么一下。
解決方法一:
但是在struct e00_date里面在加一個(gè)char或者 short。就正常了(struct 注釋的2個(gè)變量),添加變量是為了使struct的size大>=8,64位的系統(tǒng),所以猜想是這里有問(wèn)題?!但是沒(méi)道理啊,其他2,4,6大小的struct都沒(méi)問(wèn)題。。
解決方法二:
網(wǎng)上找,都說(shuō)是越界了。。然后debug一個(gè)一個(gè)找,數(shù)據(jù)都能正確的存到變量里。后面沒(méi)辦法了,一個(gè)一個(gè)的格式化輸入輸出,
scanf那,把%d改成%hu,最終就OK了。還是很納悶。。程序運(yùn)行到system("pause");最后面了,才報(bào)錯(cuò),前面都過(guò)的去,怎么這里這么就出來(lái)了。。(1.這里都沒(méi)有訪問(wèn)數(shù)據(jù)讀取了。怎么出現(xiàn)錯(cuò)誤。2.存儲(chǔ)空間數(shù)據(jù)也是正確存入了,也就是說(shuō)在short的2個(gè)字節(jié)范圍內(nèi)沒(méi)有異常數(shù)據(jù)。它憑什么就被corrupted。就算輸入1998/9/25(0x07ce/0x0009/0x0019)可能會(huì)變成(0x000007ce,0x00000009,0x00000019)最多就是把2個(gè)字節(jié)以外的0丟失嘛。。
?
真心搞不通啊。是不是理解有錯(cuò)~~求解釋~~~~~
?
轉(zhuǎn)載于:https://my.oschina.net/singlem1905/blog/82937
總結(jié)
以上是生活随笔為你收集整理的Stack around the variable 'date' was corrupted.的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 更新系统时跳过某个软件包
- 下一篇: C语言字符串拷贝