剛接觸VS2015,在.net3.5 x86下寫了個c程序。
#include
int main(void)
{
const int WEEK = 7;
int days, weeks,left;
printf("Please enter the numbers of days.\n");
printf("Enter 0 to quit.\n");
scanf_s("%d", &days):
{
left = days % WEEK;
weeks = days / WEEK;
printf("%d days is %d weeks and %d days left.\n", days, weeks, left);
scanf_s("%d", &days);
};
return 0;
}
第一次正常,第二輸入就錯誤。
0x55FAB0E2 (ucrtbased.dll)處(位於 A5.11.3 days to weeks.exe 中)引發的異常: 0xC0000005: 寫入位置 0x00000014 時發生訪問沖突。
這種情況是什麼問題?
scanf_s("%d", days, 8);
->
scanf_s("%d", &days, 8);