| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 312 人关注过本帖
标题:求关于二进制文件的基本概念以及用法
只看楼主 加入收藏
w5711423
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-12-24
结帖率:0
收藏
已结贴  问题点数:10 回复次数:1 
求关于二进制文件的基本概念以及用法
老师布置了一个学生系统的编程任务,虽然已经把基本代码写出来了,可是关于文件保存(即程序实现时数据的保存)因为查不到资料无法前进,故想请一个高手帮忙,教我有关关于程序运行结束后如何将里面数据保存,下次运行时还能用到~学生系统代码如下,希望能得到帮助。。。。
#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<stdlib.h>
#include<math.h>
#include<iomanip.h>
struct student
{
    char num[10];
    char name[15];
    float english;
    float math;
    float computer;
};
student o[100];
void print(student pr)
{
    cout<<pr.num<<setw(4)<<pr.name<<setw(4)<<pr.english<<setw(4)<<pr.math<<setw(4)<<
}

void remain()
{
    cout<<"please follow the order input"<<endl;
    cout<<"num"<<"     "<<"name"<<"     "<<"english"<<"     "<<"math"<<"     "<<"computer"<<endl;
}

void main ()
{
    int n=0;

    while(1)
    {
    zzh:printf("按1键对数据进行增加\n");
        printf("按2键对数据进行删除\n");
        printf("按3键对数据进行显示\n");
        printf("按4键退出程序\n");
        int x;
        scanf("%d",&x);
        
        
        if(x==1)
        {
            while(1)
            {
            printf("please input the information of the student\n");
            printf("please input the number of the student you want add\n");
            int a,i;
            scanf("%d",&a);
            
            for(i=n;i<a+n;i++)
            {
                remain();
                cin >> o[i].num >> o[i].name >> o[i].english >> o[i].math >> o[i].computer;

            }   
            n=a+n;
            int z;
            for(z=0; z<n; z++)
                print(o[z]);
            printf("press the 'q' and out the step of add\n");
            char u;
            scanf("%c",&u);
            if(u=='q')
                goto zzh;                    // 程序为什么要运行两次之后才能退出循环~
            
            }
        }
   
        if(x==2)
        {
            
            lp:printf("please input the data you want cancel\n");
            int j,l,p,r;
            scanf("%d",&l);
            scanf("%d",&p);
            if(p>=n)
            {
            printf("the data wasn't enough,so please input again\n");
            printf("press the 'q' and out the step of cancle.\n");
            char u;
            scanf("%c",&u);
            if(u=='q')
            goto zzh;
            goto lp;
            }
            r=p+1;
            for(j=l;j<n;j++)             //对l~p的数据进行删除,用后面数据覆盖前面数据,改变n的值达到删除的目的。
            {
                o[j]=o[r];                //从0开始的新类型~   理解错误~
                r++;
               
            }
            n=n-p+l-1;
            int q;
            for(q=0;q<n;q++)
            print(o[q]);
        
        
               
               
            
        }
   
        
                if(x==3)
                {
                    while(1)
                    {
                    printf("what function do you want\n");
                    printf("press '1' will print all the date\n");
                    printf("press '2' will print the date alone\n");
                    printf("press '3' will print the date you want as fllows\n ");
                    printf("the date limit 0~%d\n",n);
                    int y;
                    scanf("%d",&y);
                    int d,v,e;
                    if(y==1)
                    {
                        for(d=0;d<n;d++)
                            print(o[d]);
                    }
                    if(y==2)
                    {
                        scanf("%d",d);
                        print(o[d]);
                    }
                    if(y==3)
                    {
                        scanf("%d",&e);
                        scanf("%d",&v);
                        for(d=e;d<=v;d++)
                            print(o[d]);
                    }
                    char t;
                    scanf("%c",&t);
                    if(t=='q')
                        break;
                    }
                }
               
        
                if(x==4)
                    break;
        
    }
}
搜索更多相关主题的帖子: 二进制 老师 学生 
2010-12-24 08:47
zhaoya881010
Rank: 9Rank: 9Rank: 9
来 自:芒砀古郡
等 级:蜘蛛侠
威 望:1
帖 子:339
专家分:1177
注 册:2010-11-21
收藏
得分:10 
看看

Go Go Go
2010-12-24 08:49
快速回复:求关于二进制文件的基本概念以及用法
数据加载中...
 
   



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

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