在复习C语言的时候写了很简单的一个结构,代码如下:
#include
#include
struct student
{
char name[20];
int chinese;
int math;
double average;
};
void main()
{
student st[3];
int i,n;
printf("请输入学生个数\n");
scanf_s("%d", &n);
printf("请输入学生的姓名 语文成绩 数学成绩\n");
for (i = 0; i < n; i++)
{
scanf_s("%s %d %d", st[i].name, &st[i].chinese, &st[i].math);
st[i].average = (st[i].chinese + st[i].math ) / 2.0;
}
for (i = 0; i < n; i++)
printf("%s 平均成绩为:%f\n", st[i].name, st[i].average);
system("pause");
}
求问各位大佬调试的时候为什么会报错 “0x008C0B5C (ucrtbased.dll)处(位于 ConsoleApplication1.exe 中)引发的异常: 0xC0000005: 写入位置 0x3C900000 时发生访问冲突。”
为什么C语言报错写入位置时发生访问冲突?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- Lmikic 2017-08-17 10:32关注
//将输入部分修改一下:
for (i = 0; i < n; i++)
{
scanf_s("%s", st[i].name, 20);
scanf_s("%d %d", &st[i].chinese, &st[i].math);
st[i].average = (st[i].chinese + st[i].math) / 2.0;} //scanf_s在读入字符串的时候要加入size大小
解决 7无用