在做 c primer plus练习时候遇到的问题
5单元第三题有个这样的题目,把天数 换算成 星期数和天数。
[code=C/C++][/code]#include<stdio.h>
int main(void)
{const int d_to_w=7;
int s_day,week,p_day;
printf("Enter the number of days:\n");
scanf("%d",&s_day);
while(s_day>0)
{printf("%d days are %d weeks,%d days.\n",s_day,s_day/d_to_w,s_day%d_to_w);
printf("Enter the number of days:\n");
scanf("%d",s_day);
}
return 0;}
这段编译无错,2警告。
运行第一次 无错,第二次输入时 出现 OX004020C8 指令应用的 内存,该内存不能为“written”。终止。
这是什么原因呢,这个编程的思路,用过,但是这次是不是因为变量名用了太多”_“?
[解决办法]
最后一个
scanf("%d",s_day);
没加取地址符.
这样
scanf("%d",&s_day);
[解决办法]
scanf("%d",s_day);