| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 620 人关注过本帖
标题:实在是看不明白。。。。。。。
只看楼主 加入收藏
joanneken
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-9-11
收藏
 问题点数:0 回复次数:5 
实在是看不明白。。。。。。。
这个是老师给我发的一个代码  但是我实在是看不明白。哪位大哥来帮忙看下呗 解释下是啥意思~

#include  "common.h"
void main()
{
    FILE *fp = NULL;
    struct student TmpS;
    char DataFile[40] = "";
    int count = 1; /*Circular variable is to control maximum of input data.*/
    printf("\nplease input the file name to store data,end with enter.");
    printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters)\n");
    scanf("%s",DataFile);
    while(DataFile[0] == ('\0'))
    {
        printf("\nplease input new file name to store data,end with enter.");
        printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters,\npart of exceed will be discarded.)\n");
        scanf("%s",DataFile);
    }

    fp = fopen(DataFile,"wb+");
    if (fp == NULL)
    {
        printf("\n Open file %s fail!End with any key.\n",DataFile);
        return;
    }

    printf("Please input student infomation.\n0 means end.\n");
    printf("(Notice:Number is not exceed 9 figures;Name is not exceed 20 characters;Range of grade:0~100)\n");
    while(count <= SIZE) /* It's to control recorders less then maximum of stated input data. */
    {
        printf("\n Student number:");
        scanf("%d",&TmpS.number);
        if (TmpS.number == 0 )
            break;
        
        printf("Student name:");
        scanf("%s",TmpS.name);
        
        printf("Englishscore:");
        scanf("%d",&TmpS.score);
        
        printf("\n");
        if(fwrite(&TmpS,sizeof(LENGTH),1,fp)!=1)
        {
            printf("\nwrite file %s fail!End with any key\n",DataFile);
            return;
        }
        count++;
    }

    if (count>SIZE)
        printf("\nsorry,number of data can not exceed %d\n",SIZE);
    fclose(fp);
   
    /*====Showing content of file on screen.====*/
    printf("The data has stored successfully in file %s.\n",DataFile);
    printf("Content as follow:\n");
   
    fp=fopen(DataFile,"rb");
    if (fp == NULL)
    {
        printf("\nOpen file%sfail!End with any key \n",DataFile);
        return;
    }
    while(fread(&TmpS,sizeof(LENGTH),1,fp) != (int)NULL)
    {
        printf("\n%9ld\t%s\t%8d\n",TmpS.number,TmpS.name,TmpS.score);
    }
    fclose(fp);

}
搜索更多相关主题的帖子: control include exceed store count 
2008-09-11 14:34
shuxinyang
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-8
收藏
得分:0 
怎么都喜欢大片的贴代码
2008-09-11 15:33
joanneken
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-9-11
收藏
得分:0 
因为实在是看不明白。。不知道要怎么问。。。才好~
2008-09-11 15:55
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
很差的代码,看到好几个缺陷和错误。

直接填写结构体是没有可移植性的。因为计算机的enddens不一样,而且由于pack的不同,会很容易导致读取失败和数据破坏。

另外,里面很多错误处理方式都没有效果……

好好Debug吧……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-09-11 23:52
joanneken
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-9-11
收藏
得分:0 
谢谢楼上的 回答
但是可以告诉我下 哪的错误比较严重啊  具体说1~2个就行   谢谢了~
2008-09-12 13:38
hoodlum1980
Rank: 2
来 自:浙江大学
等 级:论坛游民
威 望:2
帖 子:289
专家分:23
注 册:2008-2-24
收藏
得分:0 
从代码上来看,是输入一些信息到结构体里,然后把结构体写入到文件,然后再从文件里把它们读出来显示一下。
2008-09-12 18:11
快速回复:实在是看不明白。。。。。。。
数据加载中...
 
   



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

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