| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 587 人关注过本帖
标题:改了两天了,数据总是不能读取和输入,求各位大神帮我看看到底哪里有问题, ...
只看楼主 加入收藏
makuo
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2015-4-4
结帖率:100%
收藏
 问题点数:0 回复次数:9 
改了两天了,数据总是不能读取和输入,求各位大神帮我看看到底哪里有问题,谢谢
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 3  //学生人数
#define M 5   //科目数
char s[20];//文件名
int id;
struct Student
{
    int num;
    char name[20];
    float score[N];
    float sum;
    float Average;
    int age[N];
    char sex[10];
}stu[N],temp;
void menu(void)
{
    int i;
    printf("----------------------------------by HelΙo-----------------------------------\n");
    printf("              ");
    for (i = 0; i< 50; i++)
        printf("*");
    printf("\n");
    printf("              #                                                #\n");
    printf("              #    1.载入成绩     2.成绩统计     3.显示成绩    #\n");
    printf("              #    4.查询成绩     5.录入成绩     6.修改成绩    #\n");
    printf("              #    7.保存成绩     8.删除成绩     9.成绩排名    #\n");
    printf("              #          ‘+’键退出     按0键返回菜单         #\n");
    printf("              #                                                #\n");
    printf("              ");
    for (i = 0; i < 50; i++)
        printf("*");
    printf("\n");
}
void load(void)
{
    FILE *wj;
    int i;
    printf("请输入要打开的文件,若不存在则创建.(文件名应包含扩展名):\n");
    scanf("%s", s);
    if ((wj = fopen(s, "at+")) == NULL)
    {
        printf("打开失败:\n");
    }
    for (i = 0; i < N; i++)
    {
        if (fscanf(wj, "%lld %s   %s   %d   %d   %d   %d %d  %f", &stu[i].num, stu[i].name, stu[i].sex, &stu[i].score, &stu[i].sum, &stu[i].Average) == -1)
        break;
        i++;
    }
    printf("从%s处读取了%d条记录.\n", s, N);
    fclose(wj);
}
void show(void)
{
    int i;
    printf(" ");
    for (i = 0; i < 72; i++)
        printf("*");
    printf("\n");
    printf("|    学号   姓名   性别            计算机   总 分    平均分   |\n");
    for (i = 0; i < N; i++)
        printf("|%-12lld   %-6s    %s   %5d  %5d  %5d    %5d     %5d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex,
        stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
    printf(" ");
    for (i = 0; i < 72; i++)
        printf("*");
    printf("\n");
}
void statistics (void)//统计
{
    int i;
    for (i = 0; i < N ; i++)
    {
    stu[i].sum = stu[i].score[0] + stu[i].score[1] + stu[i].score[2] + stu[i].score[3]+stu[i].score[4];
    stu[i].Average = float(stu[i].sum) / M;
    }
}
int New(void)//录入成绩
{
    int i, j;
    i = 1;
    while (1)
    {
        printf("是否录入?录入请按“1”,返回上一层请按0:\n");
        scanf("%d", &j);
        if (j == 1)
            break;
        else if (j == 0)
            return 0;
        else
            printf("输入错误,请重新输入\n");
    }
    while(1)
    {
        int A=N+1;
        printf("请输入要录入的第%d个的同学的相关信息(用空格键分开):\n", i);
        printf("    学号      姓名 性别 语 数 英 计算机\n");
        scanf("%lld %s %s %d %d %d %d", &stu[A + i - 2].num, stu[A + i - 2].name, stu[A + i - 2].sex,&stu[A + i - 2].score[0],&stu[A + i - 2].score[1],&stu[A+ i - 2].score[2],&stu[A + i - 2].score[3],&stu[A + i - 2].score[4]);
        stu[A + i - 2].Average = float(stu[A + i - 2].sum) / M;
        while(1)
        {
        printf("是否继续录入?继续请按“1”,返回菜单请按“0”\n");
        scanf("%d", &j);
        if (j == 1)
            break;
        else if (j == 0)
            return 0;
        else
            printf("输入错误,请重新输入\n");
        }
    }
    return 0;
}
int search(void)
{
    int i, j, k, l;
    char a[12];
    while (1)
    {
        printf("请选择按什么查询。\n1.按学号。\n2.按名字。\n");
        scanf("%d", &i);
        if (i == 1)
        {
            l = 0;
            printf("请输入学号:\n");
            scanf("%12d", &id);
            for (i = 0; i < N; i++)
            {
                if (stu[i].num = id)
                {
                    printf(" \n");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    l++;//判断是否有查询到
                    break;
                }
            }
            if (l == 0)
                    printf("查无此人\n");
        }
        else if (i == 2)
        {
            l = 0;
            printf("请输入姓名:\n");
            scanf("%s", a);
            for (i = 0; i < N; i++)
            {
                if ((strcmp(stu[i].name, a) == 0))
                {
                    printf(" ");
                    for (k = 0; k < 72; k++)
                    printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n", stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                    printf("*");
                    printf("\n");
                    l++;
                    break;
                }
            }
            if (l != 1)
            printf("查无此人\n");
        }
        else
            printf("输入错误.\n");
        printf("是否继续查询?是请按‘1’,否请按‘0’.\n");
        scanf("%d", &j);
        if (j == 1)
            ;
        else if (j == 0)
            return 0;
        else
            printf("输入错误\n");
    }
}
int change (void)
{
    int i, j, k, l,x;
    char a[12];
    while(1)
    {
        printf("请选择序号:\n1.输入学号修改成绩。\n2.输入姓名修改成绩。\n");
        scanf("%d", &j);
        if (j == 1)
        {
            printf("请输入学号:\n");
            scanf("%lld", &id);
            l = 0;
            for (i = 0; i < N; i++)
            {
                if (stu[i].num == id)
                {
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("请输入修改后的成绩依次为:\n");
                    for(x=0;x<M;x++)
                    {
                        printf("请输入第%d门学科的成绩\n");
                        scanf("%d",&stu[i].score[x]);
                    stu[i].sum = stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4];
                    stu[i].Average = float(stu[i].sum) /M;
                    }
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    l++;//判断是否有查询到
                    break;
                }
            }
            if (l == 0)
        printf("查无此人\n");
        }
        else if (j == 2)
        {
            printf("请输入姓名:\n");
            scanf("%s", a);
            l = 0;
            for (i = 0; i < N; i++)
            {
                if ((strcmp(stu[i].name, a) == 0))
                {
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                     printf("请输入修改后的成绩依次为:\n");
                    for(x=0;x<M;x++)
                    {
                        printf("请输入第%d门学科的成绩\n");
                        scanf("%d",&stu[i].score[x]);
                    stu[i].sum = stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4];
                    stu[i].Average = float(stu[i].sum) /M;
                    }
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    l++;//判断是否有查询到
                    break;
                }
            }
            if (l == 0)
        printf("查无此人\n");
        }
        else
        {
            printf("输入错误:\n");
        }
        printf("是否继续修改?是请按‘1’,否请按‘0’.\n");
        scanf("%d", &j);
        if (j == 1)
            ;
        else if (j == 0)
            return 0;
        else
            printf("输入错误\n");
    }
}   
int ranking(void)//排名
{
    int i, j, k, l;
    while(1)
    {
    printf("请选择按什么排列:\n1.学号。\n2.总分或平均分。\n3.单科排名。\n");
    scanf("%d", &k);
    if (k == 1)
    {
        for (i = 0; i< N; i++)
            for (j = i + 1; j < N; j++)
            {
                if (stu[i].num > stu[j].num)
                {
                    temp = stu[i];
                    stu[i] = stu[j];
                    stu[j] = temp;
                }
            }
            return 0;
    }
    else if (k == 2)
    {
        for (i = 0; i< N - 1; i++)
            for (j = i + 1; j < N; j++)
            {
                if (stu[i].sum < stu[j].sum)
                {
                    temp = stu[i];
                    stu[i] = stu[j];
                    stu[j] = temp;
                }
            }
            return 0;
    }
    else if (k == 3)
    {
        printf("请输入按哪一科排名?\n1.语文\n2.数学\n3.英语\n4.计算机\n");
        scanf("%d", &l);
        if (l == 1)
        {
            for (i = 0; i< N-1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[0] < stu[j].score[0])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 2)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[1] < stu[j].score[1])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 3)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[2]< stu[j].score[2])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 4)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[3] < stu[j].score[3])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 5)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[4] < stu[j].score[4])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else
        {
            printf("输入错误。\n");
            return 0;
        }
    }
    else
        printf("输入错误,请重新输入。\n");
    }
}
int save(void)
{
    FILE *fp;
    int i, t;
    char a[20];
    while(1)
        {
            printf("是否确认保存?确认请按‘1’,返回请按‘0’。\n");
            scanf("%d", &t);
            if (t == 1)
                break;
            else if (t == 0)
                return 0;
            else
                printf("输入错误,请重新输入。\n");
    }
    printf("请输入文件名,若文件已存在则覆盖(文件名应含扩展名):\n");
    scanf("%s", a);
    fp = fopen(a,"w");
    for (i = 0; i < N; i++)
        fprintf(fp, "%lld %s %s %d %d %d %d %d %f\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
    fclose(fp);
    printf("保存完毕\n");
    printf("在文件%s处储存了%d条记录.\n", a, N);
    return 0;
}
int del(void)
{
    int i, j, l, m,x;
    char a[12];
    x=N;
    while (1)
    {
        printf("请选择按什么删除。\n1.按学号。\n2.按名字。\n");
        scanf("%d", &i);
        if (i == 1)
        {
            l = 0;
            printf("请输入学号:\n");
            scanf("%lld", &id);
            while(1)
            {
            printf("确定删除?确定请按‘1’,取消请按‘0’。\n");
            scanf("%d", &m);
            if (m == 1)
                break;
            else if (m == 0)
                return 0;
            else printf("输入错误,请重新输入:\n");
            }
            for (i = 0; i < N; i++)
            {
                if (stu[i].num== id)
                {
                    for(; i < N - 1;i++)
                        stu[i] = stu[i + 1];
                    x--;//总人数减1
                    l++;//判断是否有此人
                    break;
                }
            }
            if (l == 0)
        printf("查无此人\n");
        }
        else if (i == 2)
        {
            l = 0;
            printf("请输入姓名:\n");
            scanf("%s", a);
            while(1)
            {
            printf("确定删除?确定请按‘1’,取消请按‘0’。\n");
            scanf("%d", &m);
            if (m == 1)
                break;
            else if (m == 0)
                return 0;
            else printf("输入错误,请重新输入:\n");
            }
            for (i = 0; i < N; i++)
            {
                if ((strcmp(stu[i].name, a) == 0))
                {
                    for(; i <N - 1;i++)
                        stu[i] = stu[i + 1];
                    x--;//总人数减1
                    l++;//判断是否有此人
                    break;
                }
            }
            if (l != 1)
            printf("查无此人\n");
        }
        else
            printf("输入错误.\n");
        printf("是否继续删除?是请按‘1’,否请按‘0’.\n");
        scanf("%d", &j);
        if (j == 1)
            ;
        else if (j == 0)
            return 0;
        else
            printf("输入错误\n");
    }
}
int main(void)
{
    menu();
    char i;
    while(1)
    {
        printf("请输入要使用的功能的序号:\n");
        scanf("%c", &i);
        if (i == '1')
        {
            load();
            system("pause");
            system("cls");
            menu();
            printf("已载入。\n");
        }
        else if (i == '2')
        {
            statistics();
            show();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '3')
        {
            show();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '4')
        {
            search();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '5')
        {
            New();
            show();
            system("pause");
            system("cls");
            menu();
            printf("已录入。\n");
        }
        else if (i == '6')
        {
            change();
            system("pause");
            system("cls");
            menu();
            printf("已修改。\n");
        }
        else if (i == '7')
        {
            save();
            system("pause");
            system("cls");
            menu();
            printf("已保存。\n");
        }
        else if (i == '8')
        {
            del();
            system("pause");
            system("cls");
            menu();
            printf("已删除。\n");
        }
        else if (i == '9')
        {
            ranking();
            show();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '0')
        {
            menu();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '+')
            exit(1);
        getchar();
    }
    return 0;
}

[ 本帖最后由 makuo 于 2015-4-27 22:52 编辑 ]
搜索更多相关主题的帖子: include 
2015-04-27 22:50
makuo
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2015-4-4
收藏
得分:0 
为什么没法在电脑上编辑...
2015-04-27 22:51
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
这代码叫人怎么看

授人以渔,不授人以鱼。
2015-04-28 19:23
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:0 
什么叫没法编辑?你把程序改的简洁一点,把主函数中if  else改成switch结构。分别测试每个函数看问题出在哪个函数

一片落叶掉进了回忆的流年。
2015-04-28 20:12
makuo
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2015-4-4
收藏
得分:0 
回复 4楼 诸葛欧阳
嗯嗯
2015-04-28 20:15
makuo
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2015-4-4
收藏
得分:0 
回复 4楼 诸葛欧阳
之前用360浏览器进论坛后屏幕上的字都是重合到一起的,没法找到编辑帖子那一项后来改用QQ浏览器才把代码传上去的
2015-04-28 20:17
makuo
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2015-4-4
收藏
得分:0 
回复 3楼 TonyDeng
嘿嘿
2015-04-28 20:17
请叫我IT楠
Rank: 2
来 自:未来星系
等 级:论坛游民
帖 子:12
专家分:23
注 册:2015-4-25
收藏
得分:0 
这么代码,6666

小弟初来咋到
2015-04-28 21:07
加油加哟
Rank: 2
等 级:论坛游民
帖 子:18
专家分:23
注 册:2015-4-13
收藏
得分:0 
把有问题和过程(实现的代码)列出来,不然太长了。
2015-04-28 22:52
鲤鱼爱美丽
Rank: 8Rank: 8
来 自:冥界
等 级:蝙蝠侠
威 望:5
帖 子:288
专家分:843
注 册:2015-4-8
收藏
得分:0 
我已经尽力了,代码真的好长啊啊
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 3  //学生人数
#define M 5//科目数
char s[20];//文件名
int id;
struct Student
{
    int num;
    char name[20];
    float score[N];
    float sum;
    float Average;
    int age[N];
    char sex[10];
}stu[N],temp;
void menu(void)
{
    int i;
    printf("----------------------------------by HelΙo-----------------------------------\n");
    printf("              ");
    for (i = 0; i< 50; i++)
        printf("*");
    printf("\n");
    printf("              #                                                #\n");
    printf("              #    1.载入成绩     2.成绩统计     3.显示成绩    #\n");
    printf("              #    4.查询成绩     5.录入成绩     6.修改成绩    #\n");
    printf("              #    7.保存成绩     8.删除成绩     9.成绩排名    #\n");
    printf("              #          ‘+’键退出     按0键返回菜单         #\n");
    printf("              #                                                #\n");
    printf("              ");
    for (i = 0; i < 50; i++)
        printf("*");
    printf("\n");
}
void load(void)
{
    FILE *wj;
    int i;
    printf("请输入要打开的文件,若不存在则创建.(文件名应包含扩展名):\n");
    scanf("%s",&s);
    if ((wj = fopen(s, "at+")) == NULL)
    {
        printf("打开失败:\n");
    }
    for (i = 0; i < N; i++)
    {
        if (fscanf(wj, "%lld %s   %s   %d   %d   %d   %d %d  %f", &stu[i].num, stu[i].name, stu[i].sex, &stu[i].score, &stu[i].sum, &stu[i].Average) == -1)
        break;
        i++;
    }
    printf("从%s处读取了%d条记录.\n", s, N);
    fclose(wj);
}
void show(void)
{
    int i;
    printf(" ");
    for (i = 0; i < 72; i++)
        printf("*");
    printf("\n");
    printf("|    学号   姓名   性别            计算机   总 分    平均分   |\n");
    for (i = 0; i < N; i++)
        printf("|%-12lld   %-6s    %s   %5d  %5d  %5d    %5d     %5d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex,
        stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
    printf(" ");
    for (i = 0; i < 72; i++)
        printf("*");
    printf("\n");
}
void statistics (void)//统计
{
    int i;
    for (i = 0; i < N ; i++)
    {
    stu[i].sum = stu[i].score[0] + stu[i].score[1] + stu[i].score[2] + stu[i].score[3]+stu[i].score[4];
    stu[i].Average = stu[i].sum/M;
    }
}
int New(void)//录入成绩
{
    int i, j;
    i = 1;
    while (1)
    {
        printf("是否录入?录入请按“1”,返回上一层请按0:\n");
        scanf("%d", &j);
        if (j == 1)
            break;
        else if (j == 0)
            return 0;
        else
            printf("输入错误,请重新输入\n");
    }
    while(1)
    {
        int A=N+1;
        printf("请输入要录入的第%d个的同学的相关信息(用空格键分开):\n", i);
        printf("    学号      姓名 性别 语 数 英 计算机\n");
        scanf("%lld %s %s %d %d %d %d", &stu[A + i - 2].num, stu[A + i - 2].name, stu[A + i - 2].sex,&stu[A + i - 2].score[0],&stu[A + i - 2].score[1],&stu[A+ i - 2].score[2],&stu[A + i - 2].score[3],&stu[A + i - 2].score[4]);
        stu[A + i - 2].Average = stu[A + i - 2].sum/M;
        while(1)
        {
        printf("是否继续录入?继续请按“1”,返回菜单请按“0”\n");
        scanf("%d", &j);
        if (j == 1)
            break;
        else if (j == 0)
            return 0;
        else
            printf("输入错误,请重新输入\n");
        }
    }
    return 0;
}
int search(void)
{
    int i, j, k, l;
    char a[12];
    while (1)
    {
        printf("请选择按什么查询。\n1.按学号。\n2.按名字。\n");
        scanf("%d", &i);
        if (i == 1)
        {
            l = 0;
            printf("请输入学号:\n");
            scanf("%12d", &id);
            for (i = 0; i < N; i++)
            {
                if (stu[i].num = id)
                {
                    printf(" \n");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    l++;//判断是否有查询到
                    break;
                }
            }
            if (l == 0)
                    printf("查无此人\n");
        }
        else if (i == 2)
        {
            l = 0;
            printf("请输入姓名:\n");
            scanf("%s", a);
            for (i = 0; i < N; i++)
            {
                if ((strcmp(stu[i].name, a) == 0))
                {
                    printf(" ");
                    for (k = 0; k < 72; k++)
                    printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n", stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                    printf("*");
                    printf("\n");
                    l++;
                    break;
                }
            }
            if (l != 1)
            printf("查无此人\n");
        }
        else
            printf("输入错误.\n");
        printf("是否继续查询?是请按‘1’,否请按‘0’.\n");
        scanf("%d", &j);
        if (j == 1)
            ;
        else if (j == 0)
            return 0;
        else
            printf("输入错误\n");
    }
}
int change (void)
{
    int i, j, k, l,x;
    char a[12];
    while(1)
    {
        printf("请选择序号:\n1.输入学号修改成绩。\n2.输入姓名修改成绩。\n");
        scanf("%d", &j);
        if (j == 1)
        {
            printf("请输入学号:\n");
            scanf("%lld", &id);
            l = 0;
            for (i = 0; i < N; i++)
            {
                if (stu[i].num == id)
                {
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("请输入修改后的成绩依次为:\n");
                    for(x=0;x<M;x++)
                    {
                        printf("请输入第%d门学科的成绩\n");
                        scanf("%d",&stu[i].score[x]);
                    stu[i].sum = stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4];
                    stu[i].Average = stu[i].sum /M;
                    }
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    l++;//判断是否有查询到
                    break;
                }
            }
            if (l == 0)
        printf("查无此人\n");
        }
        else if (j == 2)
        {
            printf("请输入姓名:\n");
            scanf("%s", a);
            l = 0;
            for (i = 0; i < N; i++)
            {
                if ((strcmp(stu[i].name, a) == 0))
                {
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                     printf("请输入修改后的成绩依次为:\n");
                    for(x=0;x<M;x++)
                    {
                        printf("请输入第%d门学科的成绩\n");
                        scanf("%d",&stu[i].score[x]);
                    stu[i].sum = stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4];
                    stu[i].Average = stu[i].sum/M;
                    }
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    printf("\n");
                    printf("|    学号        姓名    性别            计算机   总 分   平均分   |\n");
                    printf("|%-12lld   %-6s    %s   %3d  %3d  %3d    %3d     %3d     %6.2f   |\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
                    printf(" ");
                    for (k = 0; k < 72; k++)
                        printf("*");
                    l++;//判断是否有查询到
                    break;
                }
            }
            if (l == 0)
        printf("查无此人\n");
        }
        else
        {
            printf("输入错误:\n");
        }
        printf("是否继续修改?是请按‘1’,否请按‘0’.\n");
        scanf("%d", &j);
        if (j == 1)
            ;
        else if (j == 0)
            return 0;
        else
            printf("输入错误\n");
    }
}   
int ranking(void)//排名
{
    int i, j, k, l;
    while(1)
    {
    printf("请选择按什么排列:\n1.学号。\n2.总分或平均分。\n3.单科排名。\n");
    scanf("%d", &k);
    if (k == 1)
    {
        for (i = 0; i< N; i++)
            for (j = i + 1; j < N; j++)
            {
                if (stu[i].num > stu[j].num)
                {
                    temp = stu[i];
                    stu[i] = stu[j];
                    stu[j] = temp;
                }
            }
            return 0;
    }
    else if (k == 2)
    {
        for (i = 0; i< N - 1; i++)
            for (j = i + 1; j < N; j++)
            {
                if (stu[i].sum < stu[j].sum)
                {
                    temp = stu[i];
                    stu[i] = stu[j];
                    stu[j] = temp;
                }
            }
            return 0;
    }
    else if (k == 3)
    {
        printf("请输入按哪一科排名?\n1.语文\n2.数学\n3.英语\n4.计算机\n");
        scanf("%d", &l);
        if (l == 1)
        {
            for (i = 0; i< N-1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[0] < stu[j].score[0])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 2)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[1] < stu[j].score[1])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 3)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[2]< stu[j].score[2])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 4)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[3] < stu[j].score[3])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else if (l == 5)
        {
            for (i = 0; i< N - 1; i++)
                for (j = i + 1; j < N; j++)
                {
                    if (stu[i].score[4] < stu[j].score[4])
                    {
                        temp = stu[i];
                        stu[i] = stu[j];
                        stu[j] = temp;
                    }
                }
                return 0;
        }
        else
        {
            printf("输入错误。\n");
            return 0;
        }
    }
    else
        printf("输入错误,请重新输入。\n");
    }
}
int save(void)
{
    FILE *fp;
    int i, t;
    char a[20];
    while(1)
        {
            printf("是否确认保存?确认请按‘1’,返回请按‘0’。\n");
            scanf("%d", &t);
            if (t == 1)
                break;
            else if (t == 0)
                return 0;
            else
                printf("输入错误,请重新输入。\n");
    }
    printf("请输入文件名,若文件已存在则覆盖(文件名应含扩展名):\n");
    scanf("%s", a);
    fp = fopen(a,"w");
    for (i = 0; i < N; i++)
        fprintf(fp, "%lld %s %s %d %d %d %d %d %f\n",stu[i].num, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4],stu[i].sum, stu[i].Average);
    fclose(fp);
    printf("保存完毕\n");
    printf("在文件%s处储存了%d条记录.\n", a, N);
    return 0;
}
int del(void)
{
    int i, j, l, m,x;
    char a[12];
    x=N;
    while (1)
    {
        printf("请选择按什么删除。\n1.按学号。\n2.按名字。\n");
        scanf("%d", &i);
        if (i == 1)
        {
            l = 0;
            printf("请输入学号:\n");
            scanf("%lld", &id);
            while(1)
            {
            printf("确定删除?确定请按‘1’,取消请按‘0’。\n");
            scanf("%d", &m);
            if (m == 1)
                break;
            else if (m == 0)
                return 0;
            else printf("输入错误,请重新输入:\n");
            }
            for (i = 0; i < N; i++)
            {
                if (stu[i].num== id)
                {
                    for(; i < N - 1;i++)
                        stu[i] = stu[i + 1];
                    x--;//总人数减1
                    l++;//判断是否有此人
                    break;
                }
            }
            if (l == 0)
        printf("查无此人\n");
        }
        else if (i == 2)
        {
            l = 0;
            printf("请输入姓名:\n");
            scanf("%s", a);
            while(1)
            {
            printf("确定删除?确定请按‘1’,取消请按‘0’。\n");
            scanf("%d", &m);
            if (m == 1)
                break;
            else if (m == 0)
                return 0;
            else printf("输入错误,请重新输入:\n");
            }
            for (i = 0; i < N; i++)
            {
                if ((strcmp(stu[i].name, a) == 0))
                {
                    for(; i <N - 1;i++)
                        stu[i] = stu[i + 1];
                    x--;//总人数减1
                    l++;//判断是否有此人
                    break;
                }
            }
            if (l != 1)
            printf("查无此人\n");
        }
        else
            printf("输入错误.\n");
        printf("是否继续删除?是请按‘1’,否请按‘0’.\n");
        scanf("%d", &j);
        if (j == 1)
            ;
        else if (j == 0)
            return 0;
        else
            printf("输入错误\n");
    }
}
int main(void)
{
    char i;
    menu();
    while(1)
    {
        printf("请输入要使用的功能的序号:\n");
        scanf("%c", &i);
        if (i == '1')
        {
            load();
            system("pause");
            system("cls");
            menu();
            printf("已载入。\n");
        }
        else if (i == '2')
        {
            statistics();
            show();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '3')
        {
            show();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '4')
        {
            search();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '5')
        {
            New();
            show();
            system("pause");
            system("cls");
            menu();
            printf("已录入。\n");
        }
        else if (i == '6')
        {
            change();
            system("pause");
            system("cls");
            menu();
            printf("已修改。\n");
        }
        else if (i == '7')
        {
            save();
            system("pause");
            system("cls");
            menu();
            printf("已保存。\n");
        }
        else if (i == '8')
        {
            del();
            system("pause");
            system("cls");
            menu();
            printf("已删除。\n");
        }
        else if (i == '9')
        {
            ranking();
            show();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '0')
        {
            menu();
            system("pause");
            system("cls");
            menu();
        }
        else if (i == '+')
            exit(1);
        getchar();
    }
    return 0;
}

代码代码,带着的石头码!!!
2015-04-28 23:25
快速回复:改了两天了,数据总是不能读取和输入,求各位大神帮我看看到底哪里有问 ...
数据加载中...
 
   



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

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