输入一组学生信息提示0xC0000005: 读取位置时发生冲突,输入多组学生信息没问题

C语言 码拜 9年前 (2015-10-08) 952次浏览

#define _CRT_SECURE_NO_WARNINGS
#include”stdio.h”
#include”stdlib.h”
#include”string.h”
typedef struct student             //定义链表
{
long int Num;       //学号
char Name[20];    //姓名
int Age;          //年龄 
char Birthday[20];    //出生年月
char Sex[5];
char Adress[200]; //地址
long int Phone;    //电话
char Mail[20];    //邮箱
struct data *next;
}Student, *linklist;

linklist head;

linklist Input_info()
{
linklist p, tail = NULL;
long int Num;
p = (linklist)malloc(sizeof(Student));
printf(“请输入学生的学号:”);
scanf(“%ld”, &Num);
if (Num == 0)
return NULL;
p->Num = Num;
printf(“请输入学生的姓名:”);
scanf(“%s”, p->Name);
printf(“请输入学生的年龄:”);
scanf(“%d”, &p->Age);
printf(“请输入学生的出生年月:”);
scanf(“%s”, p->Birthday);
printf(“请输入学生的性别:”);
scanf(“%s”, p->Sex);
printf(“请输入学生的地址:”);
scanf(“%s”, p->Adress);
printf(“请输入学生的电话号码:”);
scanf(“%ld”, &p->Phone);
printf(“请输入学生的E-mail:”);
scanf(“%s”, p->Mail);
head = tail = p;
while (1)
{
printf(“请输入学生的学号:”);
scanf(“%ld”, &Num);
if (Num == 0)
return NULL;
else
{
p = (linklist)malloc(sizeof(Student));
p->next = NULL;
tail->next = p;
tail = p;
p->Num = Num;
printf(“请输入学生的姓名:”);
scanf(“%s”, p->Name);
printf(“请输入学生的年龄:”);
scanf(“%d”, &p->Age);
printf(“请输入学生的出生年月:”);
scanf(“%s”, p->Birthday);
printf(“请输入学生的性别:”);
scanf(“%s”, p->Sex);
printf(“请输入学生的地址:”);
scanf(“%s”, p->Adress);
printf(“请输入学生的电话号码:”);
scanf(“%ld”, &p->Phone);
printf(“请输入学生的E-mail:”);
scanf(“%s”, p->Mail);
}
}
 return head;
}
void Output_info()
{
linklist w = NULL;
printf(“学号   姓名   年龄   出生年月   性别   地址   电话号码   E – mail\n”);
for (w = head; w; w = w->next)
{
printf(“%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n”, w->Num, w->Name, w->Age, w->Birthday, w->Sex, w->Adress, w->Phone, w->Mail);
}
}

void Write_info()

{
FILE *fp;
linklist p = NULL;              //定义指针变量p
if ((fp = fopen(“Student.txt”, “w”)) == NULL)
{
printf(“不能打开文件\n”);
return;
}
p = head;          //定义指针变量指向链表
while (p != NULL)
{
fprintf(fp, “%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n”, p->Num, p->Name, p->Age, p->Birthday, p->Sex, p->Adress, p->Phone, p->Mail);
p = p->next;
}
fclose(fp);
}
//void Insert()                    //插入信息函数

void Num_refer()
{
linklist p;
p = head;
long Num;
printf(“请输入学生的学号:\n”);
scanf(“%ld”, &Num);
while (p != NULL)
{
if (Num == p->Num)
{
printf(“%ld\t%s\t%d\t\t%s\t%s\t%s\t%ld\t%s\n”, p->Num, p->Name, p->Age, p->Birthday, p->Sex, p->Adress, p->Phone, p->Mail);
break;
}
p = p->next;
}
if (p == NULL)
printf(“查无此人\n”);
}
int Submenu_refer()                //查询学生信息菜单函数
{
int choice;
while (1)
{
printf(“\n\t\t* * * * * * * * *查询学生信息* * * * * * * * *\n”);
printf(“\t\t*                1.按学号查询                *\n”);
printf(“\t\t*                2.按姓名查询                *\n”);
printf(“\t\t*                0.返回主菜单                *\n”);
printf(“\t\t* * * * * * * * * * * *  * * * * * * * * * * *\n”);
scanf(“%d”, &choice);
switch (choice)
{
case 1:
Num_refer();
break;
case 0:
break;
default:
printf(“无效选项\n”);
break;
}
}
return(choice);
}
int main()
{
int choice;
while (1)
{
printf(“\n\t\t* * * * * * * * *学生管理系统* * * * * * * * *\n”);
printf(“\t\t*                1.录入学生信息              *\n”);
printf(“\t\t*                2.浏览学生信息              *\n”);
printf(“\t\t*                3.查询学生信息              *\n”);
printf(“\t\t*                4.按照学号排序              *\n”);
printf(“\t\t*                0.退出系统                  *\n”);
printf(“\t\t* * * * * * * * * * * *  * * * * * * * * * * *\n”);
scanf(“%d”, &choice);
switch (choice)
{
case 0:
Write_info();
exit(0);
case 1:
Input_info();
break;
case 2:
Output_info();
break;
case 3:
Submenu_refer();
break;
default:
printf(“\n无效选项”);
break;
}
}
return 0;
}

解决方案:100分

是啊,但是你没写啊,那一句是我给你加上的。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明输入一组学生信息提示0xC0000005: 读取位置时发生冲突,输入多组学生信息没问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)