学生成绩管理系统文件录入与读取

这些也不行


void baocun()
{
    system("cls");
    printf("请输入要保存的文件名:");
    scanf("%s", filename);
    Node *p = head;
    if ((fp = fopen(filename, "w")) == NULL)
    {
        printf("\n保存失败\n");
        system("pause");
        return;
    }
    while (p != NULL)
    {
        fprintf(fp, "%s %d %d %d %d\n", p->stu.name, p->stu.num, p->stu.english, p->stu.java, p->stu.c);
        fprintf(fp,"\n");
        p = p->next;
    }
    fclose(fp);
    system("cls");
    printf("\t学生信息保存成功\t\n");
    system("pause");
    system("cls");
}
void duqu()
{
    system("cls");
    printf("请输入保存有学生信息的文件名:");
    scanf("%s", filename);

    if ((fp = fopen(filename, "a+")) == NULL)
    {
        printf("\n文件打开失败\n");
        system("pause");
        return;
    }
    if (head == NULL)
    {
        Head();
    }
    while (1)
    {
        Node *p = (Node *)malloc(sizeof(Node));
        p->next = NULL;
        if (fscanf(fp, "%s %d %d %d %d\n", p->stu.name, &p->stu.num, p->stu.english, &p->stu.java, &p->stu.c) == EOF)
        {
            break;
        }
        if (head == NULL)
        {
            p->next = head;
            head = p;
        }
        else
        {
            p->next = head;
            head = p;
        }
    }

    fclose(fp);

    system("cls");
    printf(" \t学生信息加载成功\t\n");
    system("pause");
    system("cls");
}

46行,p->stu.english前面少了&符号

修改如下,供参考:

void baocun()
{
    system("cls");
    printf("请输入要保存的文件名:");
    scanf("%s", filename);
    Node* p = head;
    if ((fp = fopen(filename, "w")) == NULL)
    {
        printf("\n保存失败\n");
        system("pause");
        return;
    }
    while (p != NULL)
    {
        fprintf(fp, "%s %d %d %d %d\n", p->stu.name, p->stu.num, p->stu.english, p->stu.java, p->stu.c);
        fprintf(fp, "\n");
        p = p->next;
    }
    fclose(fp);
    system("cls");
    printf("\t学生信息保存成功\t\n");
    system("pause");
    system("cls");
}
void duqu()
{
    system("cls");
    printf("请输入保存有学生信息的文件名:");
    scanf("%s", filename);

    if ((fp = fopen(filename, "a+")) == NULL)
    {
        printf("\n文件打开失败\n");
        system("pause");
        return;
    }
    if (head == NULL)
    {
        Head();
    }
    while (1)
    {
        Node* p = (Node*)malloc(sizeof(Node));
        p->next = NULL;
        if (fscanf(fp, "%s %d %d %d %d\n", p->stu.name, &p->stu.num, &p->stu.english, &p->stu.java, &p->stu.c) != 5)
        //if (fscanf(fp, "%s %d %d %d %d\n", p->stu.name, &p->stu.num, p->stu.english, &p->stu.java, &p->stu.c) == EOF) 修改
        {
            break;
        }
        //if (head == NULL) 修改
        //{
            p->next = head;
            head = p;
        //}                修改
        //else             修改 
        //{                修改
        //    p->next = head;修改
        //    head = p;      修改
        //}                修改
    }
    fclose(fp);

    system("cls");
    printf(" \t学生信息加载成功\t\n");
    system("pause");
    system("cls");
}