| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 360 人关注过本帖
标题:请教关于fscanf函数的问题
取消只看楼主 加入收藏
zyuce
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-11-25
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:0 
请教关于fscanf函数的问题
程序代码:
fprintf(save,"        Name          Num     Chinese     Math     English     Allscore\n");
    p1=head;
    fprintf(save,"        %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f\n",p1->Name,p1->Num,p1->Score.Chinese,p1->Score.Math,p1->Score.English,p1->Allscore);
    while(p1->next!=NULL)
    {
        p1=p1->next;
        fprintf(save,"        %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f\n",p1->Name,p1->Num,p1->Score.Chinese,p1->Score.Math,p1->Score.English,p1->Allscore);
    }
    p1->next=NULL;
    fclose(save);
    printf("保存成功!\n");



我是用如上方式将信息保存出去的
在硬盘中打开已保存的文件就是这样
图片附件: 游客没有浏览图片的权限,请 登录注册



这都没有问题   但是就不会怎么将该文件读取了


这是读取部分的代码

程序代码:
int fs=0;
    char filename[20];
    FILE *load;
    printf("请输入要读取的文件名:");
    scanf("%s",&filename);
    if((load=fopen("filename.txt","r+"))==NULL)
    {
        printf("No find!\n");
        return head;
    }
    fseek(load,72,0);
    struct student *p1;
    p1=(struct student *)malloc(length);
    fscanf(load,"        %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f",&p1->Name,&p1->Num,&p1->Score.Chinese,&p1->Score.Math,&p1->Score.English,&p1->Allscore);
    head=p1;
    for(;;)
    {
        p1=p1->next;
        p1=(struct student *)malloc(length);
        fs=fscanf(load,"        %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f",&p1->Name,&p1->Num,&p1->Score.Chinese,&p1->Score.Math,&p1->Score.English,&p1->Allscore);
        if(fs==EOF)
        {
            p1=NULL;
            break;
        }
    }
    fclose(load);
    printf("读取成功!\n");
    system("pause");
    getchar();
    return head;
搜索更多相关主题的帖子: next head 
2012-12-12 07:13
快速回复:请教关于fscanf函数的问题
数据加载中...
 
   



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

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