vs2017读取访问权限冲突问题

Rx丶 2019-04-07 12:55:46
为什么可以运行 但是录入数据的时候却不行 因为要进行大作业答辩 所以很急 求大佬解答 代码如下 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<windows.h> #define LEN sizeof(struct Student) FILE*fp; struct Student { int Num[10]; char Name[10]; char Sex[5]; char MajorClass[20]; char Birthday[20]; int Telephone[20]; char Address[30]; float Chinese[10]; float Math[10]; float English[10]; struct Student*next; }; void welcome()//欢迎界面 { printf(" ========================================================"); printf("\n"); printf("\n"); printf("\n"); printf(" 欢迎登陆学生信息管理系统"); printf("\n"); printf("\n"); printf("\n"); printf(" =======================================================\n"); }; void menu() { printf("\n"); printf("菜单"); printf("\n"); printf("--------------"); printf("①添加学生信息\n"); printf("--------------"); printf("②浏览学生信息\n"); printf("--------------"); printf("③查询学生信息\n"); printf("--------------"); printf("④删除学生信息\n"); printf("--------------"); printf("⑤修改学生信息\n"); } struct Student*creat() { int n=0; struct Student*head; struct Student*p1, *p2; p1 = p2 = (struct Student*)malloc(LEN); printf("请输入要输入的学生学号"); scanf("%s",&p1->Num); printf("请输入要输入的学生姓名"); scanf("%s",&p1->Name); printf("请输入要输入的学生性别"); scanf("%s",&p1->Sex); printf("请输入要输入的学生专业"); scanf("%s0",&p1->MajorClass); printf("请输入要输入的学生生日"); scanf("%s",&p1->Birthday); printf("请输入要录入的学生电话"); scanf("%s",&p1->Telephone); printf("请输入要录入的学生地址"); scanf("%s",&p1->Address); printf("请输入要录入的学生语文成绩"); scanf("%f",&p1->Chinese); printf("请输入要录入的学生数学成绩"); scanf("%f",&p1->Math); printf("请输入要录入的学生英语成绩"); scanf("%f",&p1->English); system("cls"); welcome(); menu(); } void viewstudent(struct Student*head) { struct Student*q; struct Student*p; p = head->next; if (p==NULL) { printf("没有学生信息!\n"); return; } while(p!=NULL) { printf("%s %s %s %s %s %s %s %f %f %f", &p->Num, &p->Name, &p->Sex, &p->MajorClass, &p->Birthday, &p->Telephone, &p->Address, &p->Chinese, &p->Math, &p->English); p = p->next; } } void findnum(struct Student*head, long search_Num) { struct Student*p; p = head; while ((p != NULL) && (p->Num != search_Num)) p = p->next; if (p != NULL) printf("%s %s %s %s %s %s %s %f %f %f", p->Num, p->Name, p->Sex, p->MajorClass, p->Birthday, p->Telephone, p->Address, p->Chinese, p->Math, p->English); else printf("没有该学生信息\n"); } void findname(struct Student*head, long search_Name) { struct Student*p; int cmp1 = 0, cmp = 0; p = head; while(p!=NULL) if (strcmp(p->Name, search_Name) != 0) { p = p->next; cmp++; } else { printf("%s %s %s %s %s %s %s %s %s %s", p->Num, p->Name, p->Sex, p->MajorClass, p->Birthday, p->Telephone, p->Address, p->Chinese, p->Math, p->English); p = p->next; cmp1 = 1; } if (cmp != 0 && cmp1 == 0) printf("没有该学生信息\n"); } void changestudent(struct Student*p1, long xiu_Num) { struct Student*p2; p2 = p1; while ((p2 != NULL) && (p2->Num != xiu_Num)) p2 = p2->next; if (p2 != NULL) { scanf("%s %s %s %s %s %s %s %s %s %s", &p2->Num, &p2->Name, &p2->Sex, &p2->MajorClass, &p2->Birthday, &p2->Telephone, &p2->Address, &p2->Chinese, &p2->Math, &p2->English); } else printf("没有该学生信息\n"); } struct Student*delstudent(struct Student*head, long del_Num) { struct Student*p, *q; p = head; q = head; while (p && (p->Num != del_Num)) { q = p; p = p->next; } if (p = NULL) printf("没有该学号"); else { if (p == head) { head = p->next; free(p); } else { q->next = p->next; free(p); } } return head; } void save(struct Studetn*head) { struct Student*p; if((fp=fopen("学生信息","w"))==NULL) { printf("打不开该文件\n"); exit(0); } p = head; while (p != NULL) { fprintf(fp, "%s\n",p->Num); fprintf(fp, "%s\n",p->Name); fprintf(fp, "%s\n",p->Sex); fprintf(fp, "%s\n",p->MajorClass); fprintf(fp, "%s\n",p->Birthday); fprintf(fp, "%s\n",p->Telephone); fprintf(fp, "%s\n",p->Address); fprintf(fp, "%f\n",p->Chinese); fprintf(fp, "%f\n",p->Math); fprintf(fp, "%f\n",p->English); p = p->next; } fclose(fp); } struct Student*read() { struct Student*head = NULL; struct Student*p = NULL; struct Student*t = NULL; int a; fp = fopen("学生信息", "r"); if ((fp = fopen("学生信息", "r")) == NULL) { printf("打不开文件!\n"); exit(0); } while (1) { t = (struct Student*)malloc(LEN); a = fscanf(fp, "%s %s %s %s %s %s %s %s %s %s", &t->Num, &t->Name, &t->Sex, &t->MajorClass, &t->Birthday, &t->Telephone, &t->Address, &t->Chinese, &t->Math, &t->English); if (a == 0 || a == -1) return head; t->next = NULL; if (p == NULL) { p = t; t = head; } else { p->next = t; p = p->next; p->next = NULL; } } fclose(fp); } int main() { int code = 0; struct Student*pt = NULL; while (code != 5) { menu(); welcome(); printf("请输入以上序号进行操作\n"); scanf("%d", &code); system("cls"); switch(code) { case 1: { system("cls"); printf("===========================添加学生信息========================\n"); pt = creat(); save(pt); system("cls"); printf("===========================添加学生信息========================\n"); printf("\n"); printf("\n"); printf("\n"); printf("***************************添加信息成功************************\n"); printf("\n"); printf("\n"); printf("\n"); printf("按回车返回主菜单"); getchar(); getchar(); system("cls"); }; break; case 2: { system("cls"); printf("===========================学生信息总表==========================\n"); printf("\n"); printf("学号 姓名 性别 专业 生日 电话 地址 语文成绩 数学成绩 英语成绩"); pt = read(); viewstudent(pt); printf("=================================================================\n"); printf("按回车键返回主菜单"); getchar(); getchar(); system("cls"); }; break; case 3: { int search = 0; system("cls"); printf("===========================查询学生信息===========================\n"); printf("\n"); while (search != 3) { printf("①按学号查询\n ②按姓名查询\n ③退出查询\n"); scanf("%d",&search); switch (search) { case 1: { long search_Num; system("cls"); printf("请输入要查询的学生号"); scanf("%d",&search_Num); system("cls"); printf("=================================查询结果============================"); printf("\n"); printf("学号 姓名 性别 专业 生日 电话 地址 语文成绩 数学成绩 英语成绩"); findnum(read(), search_Num); printf("====================================================================="); printf("\n"); printf("\n按回车键返回查询菜单\n"); getchar(); getchar(); system("cls"); }break; case 2: { char search_Name[15]; system("cls"); printf("请输入要查询的学生姓名"); scanf("%s", search_Name); system("cls"); printf("=================================查询结果============================="); printf("\n"); printf("学号 姓名 性别 专业 生日 电话 地址 语文成绩 数学成绩 英语成绩"); findname(read(), search_Name); printf("======================================================================"); printf("\n"); printf("\n 按回车健返回查询菜单\n"); getchar(); getchar(); system("cls"); }; } } system("cls"); }; break; case 4: { long del_Num; system("cls"); printf("===============================删除学生信息==========================="); printf("\n"); printf("请输入要删除学生的学号\n"); scanf("%d",&del_Num); system("cls"); pt = delstudent(read(), del_Num); save(pt); printf("=================================删除结果============================="); printf("\n"); printf("学号为%d的学生信息删除成功\n",del_Num); printf("\n 按回车键返回主菜单 \n"); getchar(); getchar(); system("cls"); }; break; case 5: { long search_Num; system("cls"); printf("请输入要修改的学生学号"); scanf("%d",&search_Num ); system("cls"); printf("=====================================修改学生信息============================\n"); printf("\n"); printf("学号 姓名 性别 专业 生日 电话 地址 语文成绩 数学成绩 英语成绩\n"); findnum(read(), search_Num); printf("\n"); printf("请输入需要修改的信息"); printf("学号 姓名 性别 专业 生日 电话 地址 语文成绩 数学成绩 英语成绩\n"); pt = read(); changestudent(pt, search_Num); save(pt); printf("=============================================================================\n"); printf("\n"); printf("***********修改信息成功***********"); printf("\n 按回车键返回主菜单 \n"); getchar(); getchar(); } } } }
...全文
700 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
藤井树441 2021-12-14

应该是越界,访问了其他地址

  • 打赏
  • 举报
回复
Rx丶 2019-04-08
引用 1 楼 qq_40162781 的回复:
应该是越界,访问了其他地址
那应该怎么改
  • 打赏
  • 举报
回复
qq_40162781 2019-04-07
应该是越界,访问了其他地址
  • 打赏
  • 举报
回复
相关推荐
发帖
其它技术问题
加入

3857

社区成员

C/C++ 其它技术问题
申请成为版主
帖子事件
创建了帖子
2019-04-07 12:55
社区公告
暂无公告