问题描述
- VS2015,用scanf_s警告,循环输入的第一次正常,第二次出错。求指点
-
刚接触VS2015,在.net3.5 x86下写了个c程序。
#includeint 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);
解决方案二:
第二处没注意到漏写地址符,谢谢
时间: 2024-10-28 06:36:08