处有未经处理的异常:0xC0000005:写入位置0x00EFA000时发生访问冲突.
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了处有未经处理的异常:0xC0000005:写入位置0x00EFA000时发生访问冲突.相关的知识,希望对你有一定的参考价值。
#include<stdio.h>
#include<stdlib.h>
struct student_type
char name[10];
int num;
int age;
stud[10];
void save(char *name, int n)
FILE *fp;
int i;
errno_t ero;
if ((ero = fopen_s(&fp, name, "wb")) != NULL)
printf("cannot open file\n");
exit(0);
for (i = 0; i < n; i++)
if (fwrite(&stud[i], sizeof(struct student_type), 1, fp) != 1)
printf("file write error\n");
fclose(fp);
int main()
FILE *fp1;
int i, n;
char filename[50];
errno_t er;
printf("please input filename:\n");
scanf_s("%s", filename, 50);
printf("please input the number of students:\n");
scanf_s("%d", &n, 2);
printf("please input name ,number,age:\n");
for (i = 0; i < n; i++)
printf("NO%d", i + 1);
scanf_s("%s", stud[i].name,10);
scanf_s("%d", stud[i].num,4);
scanf_s("%d", stud[i].age,2);
save(filename, n);
if ((er = fopen_s(&fp1, filename, "rb")) != NULL)
printf("cannot open file\n");
exit(0);
for (i = 0; i < n; i+=2)
fseek(fp1, i*sizeof(struct student_type), 0);
fread(&stud[i], sizeof(struct student_type), 1, fp1);
printf("%-10s%5d%5d\n", stud[i].name, stud[i].num, stud[i].age);
fclose(fp1);
system("pause");
return 0;
#include <stdlib.h>
struct student_type
char name[10];
int num;
int age;
stud[10];
void save(char *name, int n)
FILE *fp;
int i;
errno_t ero;
if((ero = fopen_s(&fp, name, "wb")) != NULL)
printf("cannot open file\\n");
exit(0);
for(i = 0; i < n; i++)
if(fwrite(&stud[i], sizeof(struct student_type), 1, fp) != 1)
printf("file write error\\n");
fclose(fp);
int main()
FILE *fp1;
int i, n;
char filename[50];
errno_t er;
printf("please input filename:\\n");
scanf_s("%s", filename, 50);
printf("please input the number of students:\\n");
scanf_s("%d", &n, 2);
if(n > 10) n = 10; // 不能超过10
printf("please input name ,number,age:\\n");
for (i = 0; i < n; i++)
printf("NO%d", i + 1);
scanf_s("%s", stud[i].name,10);
scanf_s("%d", &stud[i].num,4); // 要加取址符
scanf_s("%d", &stud[i].age,2); // 这儿也是
save(filename, n);
if((er = fopen_s(&fp1, filename, "rb")) != NULL)
printf("cannot open file\\n");
exit(0);
for(i = 0; i < n; i+=2)
// 这句不是必要的,文件读指针会自动移动
fseek(fp1, i*sizeof(struct student_type), 0);
fread(&stud[i], sizeof(struct student_type), 1, fp1);
printf("%-10s%5d%5d\\n", stud[i].name, stud[i].num, stud[i].age);
fclose(fp1);
system("pause");
return 0;
参考技术A for (i = 0; i < n; i+=2)
fseek(fp1, i*sizeof(struct student_type), 0); 这句放到for语句前面
fread(&stud[i], sizeof(struct student_type), 1, fp1);
printf("%-10s%5d%5d\n", stud[i].name, stud[i].num, stud[i].age);
以上是关于处有未经处理的异常:0xC0000005:写入位置0x00EFA000时发生访问冲突.的主要内容,如果未能解决你的问题,请参考以下文章
有未经处理的异常: 0xC0000005: 读取位置 0xFFFFFFFC 时发生访问冲突
C0000005: 读取位置 0xCCCCCCCC 时发生访问冲突
0x01A686F0 处有未经处理的异常(在 五金上色软件.exe 中): 0xC000041D: 用户回调期间遇到未经处理的异常。。
Project3.exe 中 0x00C61540 处未处理的异常:0xC0000005:访问冲突读取位置 0x00000003
在 filePath.exe 中的 0x793F3729 (vcruntime140d.dll) 处引发异常:0xC0000005:访问冲突写入位置 0xCDCDCDCD