标题:C语言读写文件(难)
只看楼主
一鑫
Rank: 2
等 级:论坛游民
帖 子:111
专家分:12
注 册:2018-4-12
结帖率:92.86%
已结贴  问题点数:20 回复次数:6 
C语言读写文件(难)
我是先定义一个STUDENT结构体,
简化写一下
typedef struct
{
    char name[30];
}STUDENT
然后我将数据写入一个demo.txt的文档
我是可以查到学生的数据的;
我再定义一个 TEACHER的结构体
用到了链表
typedef struct SingleNode
{
    STUDENT data;
    struct SingleNode *next;
}SingleLinkedList, *LinkList;
typedef struct
{
    char name[30];
    LinkList p;
}TEACHER;
然后我想输出TEACHER下对应的第一个STUDENT的姓名,就出错了
    printf("    %s", teacher[i].p->data.Name);

错误是0x40E3170C (ucrtbased.dll)处(位于 学生成绩管理系统.exe 中)引发的异常: 0xC0000005: 读取位置 0x008B0D48 时发生访问冲突;
为什么呢,如果有兴趣帮我解决的大佬,我可以将源代码发给你,谢谢你们
搜索更多相关主题的帖子: C语言 STUDENT typedef struct TEACHER 
2018-12-02 19:34
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:10 
#include <stdio.h>

typedef struct
{
    char name[30];
}STUDENT;

typedef struct SingleNode
{
    STUDENT data;
    struct SingleNode *next;
}SingleLinkedList, *LinkList;

typedef struct
{
    char name[30];
    LinkList p;
}TEACHER;

void main()
{
    SingleLinkedList sl[3]={"aaa",&sl[1], "bbb",&sl[2], "ccc",NULL};
    TEACHER st[3]={"AAA",&sl[0], "BBB",&sl[1], "CCC",&sl[2]};
    printf("%s\n", st[0].p->data.name);
    printf("%s\n", st[1].p->data.name);
    printf("%s\n", st[2].p->data.name);
}
2018-12-02 20:28
lin5161678
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:45
帖 子:1136
专家分:3729
注 册:2011-12-3
得分:10 
贴代码

https://zh.
2018-12-02 20:35
一鑫
Rank: 2
等 级:论坛游民
帖 子:111
专家分:12
注 册:2018-4-12
得分:0 
贴出我的代码 vs2017编译环境 其中 1 2 3 8 0功能能实现,3中的按辅导员查询还没写 7回收站是我要测试能不能输出TEACHER下的STUDENT的信息的,回收站这个名字只是懒得改 代码有点多,谢谢大家耐心帮查错!
2018-12-02 20:57
一鑫
Rank: 2
等 级:论坛游民
帖 子:111
专家分:12
注 册:2018-4-12
得分:0 
LinkedList.h
#pragma once
typedef STUDENT ElemType;
typedef struct SingleNode
{
    ElemType data;
    struct SingleNode *next;
}SingleLinkedList, *LinkList;
void ListInitialize(SingleLinkedList**head);  /*单链表初始化*/
int ListLength(SingleLinkedList *head);/*获得线性表的长度*/
int ListGet(SingleLinkedList *head, int i, ElemType *x);/*取序号为i的元素的值*/
int ListInsert(SingleLinkedList *head, int i, ElemType x);/*插入数据元素*/
int ListDelete(SingleLinkedList *head, int i, ElemType *x);/*删除元素*/
void ListDestroy(SingleLinkedList **head);
void reverse(SingleLinkedList *head);/*逆置,头插原理*/

LinkedList.cpp
#include"pch.h"
#include"LinkedList.h"
int locate_i = 0;
void ListInitialize(SingleLinkedList**head)  /*单链表初始化*/
{
    if ((*head = (SingleLinkedList *)malloc(sizeof(SingleLinkedList))) == NULL)
        exit(1);
    (*head)->next = NULL;
}
int ListLength(SingleLinkedList *head)/*获得线性表的长度*/
{
    SingleLinkedList *p = head;
    int size = 0;
    while (p->next != NULL)
    {
        p = p->next;
        size++;
    }
    return size;
}
int ListGet(SingleLinkedList *head, int i, ElemType *x)/*取序号为i的元素的值*/
{
    SingleLinkedList *p;
    int j;
    p = head;
    j = -1;
    while (p->next != NULL && j < i)
    {
        p = p->next;
        j++;
    }
    if (j != i)
    {
        printf("取元素位置参数错!");
        return 0;
    }
    *x = p->data;
    return 1;
}
int ListInsert(SingleLinkedList *head, int i, ElemType x)/*插入数据元素*/
{
    SingleLinkedList *p, *q;
    int j;
    p = head;
    j = -1;
    while (p->next != NULL && j < i - 1)
    {
        p = p->next;
        j++;
    }
    if (j != i - 1)
    {
        printf("插入位置参数错");
        return 0;
    }
    if ((q = (SingleLinkedList *)malloc(sizeof(SingleLinkedList))) == NULL)
        exit(1);
    q->data = x;
    q->next = p->next;
    p->next = q;
    return 1;
}
int ListDelete(SingleLinkedList *head, int i, ElemType *x)/*删除元素*/
{
    SingleLinkedList *p, *s;
    int j;
    p = head;
    j = -1;
    while (p->next != NULL && p->next->next != NULL && j < i - 1)
    {
        p = p->next;
        j++;
    }
    if (j != i - 1)
    {
        printf("删除位置参数错!");
        return 0;
    }
    s = p->next;
    *x = s->data;
    p->next = s->next;
    free(s);
    return 1;
}
void ListDestroy(SingleLinkedList **head)
{
    SingleLinkedList *p, *p1;
    p = *head;
    while (p != NULL)
    {
        p1 = p;
        p = p->next;
        free(p1);
    }
    *head = NULL;
}
void reverse(SingleLinkedList *head)/*逆置,头插原理*/
{
    SingleLinkedList *p, *q;
    p = head->next;
    head->next = NULL;
    while (p)
    {
        q = p; p = p->next;
        q->next = head->next;
        head->next = q;
    }

}


pch.h
#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<Windows.h>
#include<conio.h>
#define N 3000
typedef struct
{
double math;
double english;
double cLanguage;
}SCORE;
typedef struct Student
{
    char Name[N];
    char Sex[N];
    char ID[N];
    char teacher[N];
    char _class[N];
    SCORE myScore;
}STUDENT;
#include"LinkedList.h"
typedef struct
{
    char Name[N];
    LinkList p;
}TEACHER;
#define FIRSTMENU1 "               ---------------------------------------------------\n"
#define FIRSTMENU2 "                              学生成绩管理系统\n"
#define FIRSTMENU3 "               ********************主菜单*************************\n"
#define FIRSTMENU4 "               *        1 输入学生信息       2 显示学生信息      *\n"
#define FIRSTMENU5 "               *        3 查询学生信息       4 修改学生信息      *\n"
#define FIRSTMENU6 "               *        5 显示排名信息       6 删除学生信息      *\n"
#define FIRSTMENU7 "               *        7 回收站             8 保存学生信息      *\n"
#define FIRSTMENU8 "               *        0 退出系统                               *\n"
#define FIRSTMENU9 "               ***************************************************\n"
#define SECONDMENU1_1 "               *****************输入学生信息**********************\n"
#define SECONDMENU1_2 "               请开始输入信息 注意每个类型的信息之间的空格\n"
#define SECONDMENU1_3 "               *        1 继续输入           0 返回上一级菜单    *\n"
#define SECONDMENU8_1 "               *****************保存学生信息**********************\n"
#define SECONDMENU2_1 "               *****************显示学生信息**********************\n"
#define SECONDMENU3_1 "               *****************查询学生信息**********************\n"
#define SECONDMENU3_2 "               *        1 按学号查询        2 按姓名查询         *\n"
#define SECONDMENU3_3 "               *        3 按班级查询        4 按辅导员查询       *\n"
#define HEADER1 "    --------------------------------学生信息-----------------------------------------------\n"
#define HEADER2 "   |学号      |姓名      |性别      |辅导员    |班级      |高数      |英语      |C语言     | \n"
#define HEADER3 "   |----------|----------|----------|----------|----------|----------|----------|----------| \n"
void Menu();
void ScanfStuIn(STUDENT students[], STUDENT students_display[], int &count_stu,TEACHER teacher[]);
int ScanfStuInError(char ch, int flag, int *p,int *a);
void stringinput(char* t, int lens,const char *p);
void  CountDown(int n);
void SaveData(STUDENT students[],int count_stu,int flag,TEACHER teacher[]);//flag用于这个函数是直接调用还是退出是调用
int ReadfromFile(STUDENT students[]);
void Display(STUDENT students[], int count_stu);
void Search(STUDENT students_display[]);
int* Search_(STUDENT students_display[], int xiabiao[], int &p, char ch);
int InspectID(STUDENT students_display[], const char *p);
void UpdataFile(FILE *fp,STUDENT students[]);
void UpdataFile_teacher(FILE *fp_teacher, TEACHER students[]);
int ReadfromFile_Teacher(TEACHER teacher_void[]);
void Display_Teacher(TEACHER teacher[], int count_teachers);


pch.cpp
#pragma once
#include"pch.h"
int i = 0;
bool save = false;
int count_file = 0;
int count_teachers = 0;
extern int locate_i;
void CountDown(int n)
{
    while (n > 0)
    {
        printf("%d ", n);
        Sleep(1000);
        n--;
    }
    printf("\n");
}
void Menu()
{
    system("cls");
    printf(FIRSTMENU1);
    printf(FIRSTMENU2);
    printf(FIRSTMENU3);
    printf(FIRSTMENU4);
    printf(FIRSTMENU5);
    printf(FIRSTMENU6);
    printf(FIRSTMENU7);
    printf(FIRSTMENU8);
    printf(FIRSTMENU9);
}
void ScanfStuIn(STUDENT students[],STUDENT students_display[],int &count_stu,TEACHER teacher[])
{
    system("cls");
    int flag = 1,flag_=1; FILE *fp; char ch = '1';  int k=1,j,n=0,p = 0,a=0;//flag用于退出输入的循环,n是用于显示一次头顶菜单
    while (flag)
    {
        while (a==0&&p==0)
        {
            printf(FIRSTMENU1);
            printf(FIRSTMENU2);
            printf(SECONDMENU1_1);
            a = 1;
        }
        if (ch == '1')
        {
            while (1)
            {
                printf("               Id:"); stringinput(students[i].ID, 15, "Id:");
                if (InspectID(students_display, students[i].ID) != 0)
                {
                    printf("               Name:"); stringinput(students[i].Name, 15, "Name:");
                    printf("               Sex:"); stringinput(students[i].Sex, 15, "Sex:");
                    printf("               teacher:"); stringinput(students[i].teacher, 15, "teacher:");
                    if (count_teachers != 0)
                    {
                        for (j = 0; j < count_teachers; j++)
                        {
                            if (strcmp(students[i].teacher, teacher[j].Name) == 0)
                            {
                                flag_ = 0;
                                break;
                            }
                            else
                            {
                                flag_ = 1;
                                strcpy(teacher[j].Name, students[i].teacher);
                                ListInsert(teacher->p, locate_i, students[i]);
                                locate_i++;
                                count_teachers++;
                            }
                        }
                    }
                    else
                    {
                        strcpy(teacher[0].Name, students[i].teacher);
                        ListInsert(teacher->p, locate_i, students[i]);
                        locate_i++;
                        count_teachers++;
                    }
                    printf("               class:"); stringinput(students[i]._class, 15, "class:");
                        
                    i++;
                    printf("               输入成功\n");
                    save = false;
                    count_stu++;
                    printf(SECONDMENU1_3);
                    printf("              请输入你的选择:");
                    ch = '0';
                    getchar();
                    break;//用于缓冲上一个字符
                }
            }
        }
        ch = getchar();
        flag=ScanfStuInError(ch,flag,&p,&a);
    }
    //加一个以学号为基础的统计学生个数函数
}
int ScanfStuInError(char ch,int flag,int *p,int *a)
{
    system("cls");
    if (ch == '0')
    {
        p = 0;
        return 0;
    }
    else if (ch == '1')
    {
        *p = 0;
        *a = 0;

        return 1;
    }
    else
        while (flag)
        {
            printf(FIRSTMENU1);
            printf(FIRSTMENU2);
            printf(SECONDMENU1_1);
            printf("              你的输入不符合要求,请按要求输入\n");
            printf(SECONDMENU1_3);
            *p = 1;
            return 1;
        }
}
void stringinput(char* t, int lens,const char *p)
{

    char str[255];
    do
    {
        scanf("%s", str);
        //进行长度校验,超过lens值重新输入   
        if (strlen(str) > lens)
        {
            printf("               超过规定长度!\n");
            printf("               %s", p);
        }
    } while (strlen(str)>lens);
    //将输入的字条串保存到字符串t中
    strcpy(t, str);
}
void SaveData(STUDENT students[],int count_stu,int flag,TEACHER teacher[])
{
    if (count_stu == 0)
    {
        if (flag == 0)
        {
            system("cls");
            printf(FIRSTMENU1);
            printf(FIRSTMENU2);
            printf("               ******************确认退出中***********************\n");
            printf("                               无可保存的数据,自动退出:");
            CountDown(3);
            exit(0);
        }
        else
        {
            system("cls");
            printf(FIRSTMENU1);
            printf(FIRSTMENU2);
            printf("               ******************确认退出中***********************\n");
            printf("                               无可保存的数据,自动返回上一级菜单");
            CountDown(3);
            return;
        }
    }
    system("cls");
    FILE *fp;
    if ((fp = fopen("D:\\demo.txt", "a")) == NULL)
    {
        printf("               文件保存失败\n");
        exit(0);
    }
    fwrite(students, sizeof(STUDENT), count_stu, fp);
    fclose(fp);
    printf(FIRSTMENU1);
    printf(FIRSTMENU2);
    printf(SECONDMENU8_1);
    printf("               保存成功  ");
    save = true;
    fp = fopen("D:\\demo.txt", "r");
    UpdataFile(fp, students);
    fclose(fp);
    FILE *fp_teacher;
    if ((fp_teacher = fopen("D:\\teacher.txt", "a")) == NULL)
    {
        exit(0);//崩程序
    }
    fwrite(teacher, sizeof(TEACHER), count_teachers, fp_teacher);
    fclose(fp_teacher);
    fp_teacher = fopen("D:\\teacher.txt", "r");
    UpdataFile_teacher(fp_teacher, teacher);
    fclose(fp_teacher);
    system("pause");
}
int ReadfromFile(STUDENT students[])
{
    system("cls");
    FILE *fp; int i;
    if ((fp = fopen("D:\\demo.txt", "r")) == NULL)
    {
        printf("               文件保存失败\n");
        exit(0);
    }
    for (i = 0; !feof(fp); i++)
    {
        fread(&students[i], sizeof(STUDENT), 1, fp);
    }
    fclose(fp);
    return i - 1;
}
void Display(STUDENT students[], int count_stu)
{
        int i = 0;
        system("cls");
        printf(FIRSTMENU1);
        printf(FIRSTMENU2);
        printf(SECONDMENU2_1);
        printf(HEADER1);
        printf(HEADER2);
        printf(HEADER3);
        for (i; i < count_stu; i++)
        {
            printf("    %s", students[i].ID);
            printf("  %s", students[i].Name);
            printf("       %s", students[i].Sex);
            printf("       %s", students[i].teacher);
            printf("       %s", students[i]._class);
            printf("\n");
        }
    system("pause");
}
void Search(STUDENT students_display[])
{
    int i = 0; char c[N]; char select; int flag = 0, count = 0;
    int xiabiao[N];
    system("cls");
    printf(FIRSTMENU1);
    printf(FIRSTMENU2);
    printf(SECONDMENU3_1);
    printf(SECONDMENU3_2);
    printf(SECONDMENU3_3);
    printf("               *               0 返回上一级菜单                  *\n");
    printf("               请输入你的选择:");
    while (1)
    {
        scanf("%s", c);
        //stringinput(c, 15, "");
        if (c[1] == '\0')
        {
            select = c[0];
            if (select >= '0' && select <= '4')
            {
                switch (select)
                {
                case '1':
                    Search_(students_display, xiabiao,count,'1');
                    if (count==0)
                    {
                        printf("               查询不到该信息;");
                    }
                    else
                    {
                        for (i = 0; i < count; i++)
                        {
                            //Display(&students_display[xiabiao[i]], 1);//查不了重复的写法
                            Display(&students_display[*xiabiao], count);//可以查重复的写法
                        }
                    }
                    //按学号查询
                    break;
                case '2':
                    //按姓名查询
                    Search_(students_display, xiabiao, count, '2');
                    if (count == 0)
                    {
                        printf("查询不到该信息;");
                    }
                    else
                    {
                        for (i = 0; i < count; i++)
                        {
                            Display(&students_display[*xiabiao], count);
                        }
                    }
                    break;
                case '3':
                    Search_(students_display, xiabiao, count, '3');
                    if (count == 0)
                    {
                        printf("查询不到该信息;");
                    }
                    else
                    {
                        for (i = 0; i < count; i++)
                        {
                            Display(&students_display[*xiabiao], count);
                        }
                    }
                    //按班级查询
                    break;
                case '4':
                    //按辅导员查询
                    break;
                case '0':
                    return;
                default:
                    break;
                }
            }
            else
            {
                printf("               你的输入不符合要求,请按要求输入\n");
                printf("               ");
            }
        }
        else
        {
            printf("               你的输入不符合要求,请按要求输入\n");
            printf("               ");
        }
    }
}
//p是用来记录找到了多少个人
int* Search_(STUDENT students_display[], int xiabiao[], int &p,char ch)
{
    FILE *fp; char find[N];
    if (ch == '1')
        printf("               请输入你要查询的学号:");
    if (ch == '2')
        printf("               请输入你要查询的姓名:");
    if (ch == '3')
        printf("               请输入你要查询的班级:");
    if (ch == '4')
        printf("               请输入你要查询的辅导员:");
    scanf("%s", find);
    int i; p = 0;
    if ((fp = fopen("D:\\demo.txt", "r")) == NULL)
    {
        printf("查询失败\n");
        return NULL;
    }
    for (i = 0; !feof(fp); i++)
    {
        fread(&students_display[i], sizeof(STUDENT), 1, fp);
    }
    fclose(fp);
    if (ch == '1')
    {
        for (i = 0; i < count_file; i++)
        {
            if (strcmp(students_display[i].ID, find) == 0)
            {
                xiabiao[p++] = i;
            }
        }
    }
    else if (ch == '2')
    {
        for (i = 0; i < count_file; i++)
        {
            if (strcmp(students_display[i].Name, find) == 0)
            {
                xiabiao[p++] = i;
            }
        }
    }
    else if (ch == '3')
    {
        for (i = 0; i < count_file; i++)
        {
            if (strcmp(students_display[i]._class, find) == 0)
            {
                xiabiao[p++] = i;
            }
        }
    }
    return xiabiao;
}
int InspectID(STUDENT students_display[], const char *p)
{
    FILE *fp; int j;
    if ((fp = fopen("D:\\demo.txt", "r")) == NULL)
    {
        printf("               文件保存失败\n");
        exit(0);
    }
    for (j = 0; !feof(fp); j++)
    {
        fread(&students_display[j], sizeof(STUDENT), 1, fp);
        if (strcmp(students_display[j].ID,p)==0)
        {
            printf("               你输入的ID已存在,请重新输入:");
            CountDown(3);
            return 0;
        }
    }
    fclose(fp);
    return 1;
}
void UpdataFile(FILE *fp,STUDENT students[])
{
    while (!feof(fp))//如果是在读取函数之前进行判断,则如果文件最后一行是空白行,可能会造成内存错误。baidu
        if (fread(&students[0], sizeof(STUDENT), 1, fp) == 1)
            count_file++;
}
void UpdataFile_teacher(FILE *fp_teacher, TEACHER teachers[])
{
    while (!feof(fp_teacher))//如果是在读取函数之前进行判断,则如果文件最后一行是空白行,可能会造成内存错误。baidu
        if (fread(&teachers[0], sizeof(TEACHER), 1, fp_teacher) == 1)
            count_teachers++;
}
int ReadfromFile_Teacher(TEACHER teacher_void[])
{
    FILE *fp_teacher; int i;
    if ((fp_teacher = fopen("D:\\teacher.txt", "r")) == NULL)
    {
        printf("               文件保存失败\n");
        exit(0);
    }
    for (i = 0; !feof(fp_teacher); i++)
    {
        fread(&teacher_void[i], sizeof(TEACHER), 1, fp_teacher);
    }
    fclose(fp_teacher);
    return i - 1;
}
void Display_Teacher(TEACHER teacher[], int count_teachers)
{
    int i = 0;
    system("cls");
    printf(FIRSTMENU1);
    printf(FIRSTMENU2);
    printf(SECONDMENU2_1);
    printf(HEADER1);
    printf(HEADER2);
    printf(HEADER3);
    for (i; i < count_teachers; i++)
    {        printf("    %s", teacher[i].p->data.Name);
            printf("\n");
    }
    system("pause");
}


main.cpp
#include"pch.h"
extern bool save;
extern int count_file;
extern int count_teachers;
void main(int a)
{
    char select; int n = 0, count_stu = 0; int flag = 0;
    char c[N];
    FILE *fp,*fp_teacher;
    STUDENT students[N], students_dispaly[N];
    TEACHER teachers[N],teacher_void[N];
    ListInitialize(&teachers->p);
    fp = fopen("D:\\demo.txt", "a+");//打开保存学生信息的文件
    if (fp == NULL)
    {
        printf("               文件打开失败\n");
        exit(0);
    }
    UpdataFile(fp, students);
    fclose(fp);
    fp_teacher = fopen("D:\\teacher.txt", "a+");
    if (fp_teacher == NULL)
    {
            printf("               老师信息数据库文件打开失败\n");
            exit(0);
    }
    UpdataFile_teacher(fp_teacher, teachers);
    fclose(fp_teacher);
    Menu();
    while (1)
    {
            system("cls");
            Menu();
        printf("               请输入你的选择:");
        
        scanf(" %s",c);
        if (c[1] == '\0'&&isdigit(c[0]) != 0)
        {
            select = c[0];
            if (isdigit(select) != 0)//判断输入是不是数字
            {
                //fflush(stdin);
                if (select > '0' && select <= '8')
                {
                    switch (select)
                    {
                    case '1':
                        ScanfStuIn(students,students_dispaly,count_stu,teachers);
                        break;
                    case '2':
                        Display(students_dispaly, ReadfromFile(students_dispaly));
                        //显示学生信息
                        break;
                    case '3':
                        Search(students_dispaly);
                        //查询学生信息
                        break;
                    case '4':
                        //修改学生信息
                        break;
                    case '5':
                        //显示排名信息
                        break;
                    case '6':
                        //删除学生信息
                        break;
                    case '7':
                        Display_Teacher(teacher_void, ReadfromFile_Teacher(teacher_void));
                        //回收站
                        break;
                    case '8':
                        SaveData(students, count_stu,1,teachers);
                        //保存信息
                        break;
                    default:
                        //输入错误
                        break;
                    }
                }
                else if (select == '0')
                {
                    //还要判断是否保存了数据
                    if (save==true)
                    {
                        system("cls");
                        printf(FIRSTMENU1);
                        printf(FIRSTMENU2);
                        printf("               退出成功 感谢你的使用");
                        break;
                    }
                    else
                    {
                        system("cls");
                        printf(FIRSTMENU1);
                        printf(FIRSTMENU2);
                        printf("               ******************确认退出中***********************\n");
                        printf("                               你的数据还没有保存\n");
                        printf("                           1 保存后退出  其他 直接退出\n");
                        printf("                           选择:");
                        scanf(" %s", c);
                        select = c[0];
                        if (c[1] == '\0'&&select == '1')
                        {
                            SaveData(students, count_stu,0,teachers);
                            printf("                           保存成功,等待退出:");
                            CountDown(3);
                            exit(0);
                        }
                        else
                        {
                            printf("                           等待退出:");
                            CountDown(3);
                            exit(0);
                        }
                    }
                }
                else
                {
                    printf("               你的输入有错误,请重新输入:");
                }
            }
        }
        else
        {
            printf("               你的输入有错误,请重新输入:");
            CountDown(3);//倒计时
        }
    }
    system("pause");
}

2018-12-02 20:59
一鑫
Rank: 2
等 级:论坛游民
帖 子:111
专家分:12
注 册:2018-4-12
得分:0 
回复 3楼 lin5161678
贴出来了
2018-12-02 21:00
lin5161678
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:45
帖 子:1136
专家分:3729
注 册:2011-12-3
得分:0 
直接从文件里面读取
程序代码:
typedef struct
{
    char Name[N];
    LinkList p;
}TEACHER;

指针p 这样的操作是错的

指针只在当前进程有效
你关闭程序重新打开 这个指针就废了
相当于你访问一个野指针

正确的是做法是 链表的数据存储到文件里面
读文件的时候 重新创建链表 节点的next 要重新malloc 然后从文件里面读取出数据填充到节点里面

https://zh.
2018-12-03 09:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-491761-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.880374 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved