标题:关于fscanf和fprintf的简单操作,哪儿出错了啊?
只看楼主
境善
Rank: 2
等 级:论坛游民
帖 子:76
专家分:16
注 册:2012-10-29
结帖率:86.21%
已结贴  问题点数:1 回复次数:1 
关于fscanf和fprintf的简单操作,哪儿出错了啊?
#include <stdio.h>
#include <string.h>   
#include <stdlib.h>
struct student
    {
    char name[20];
    int num;
    char flag;
    }stu[3];
void main()
{
FILE *fin;
FILE *fout;
    char name[20];
    int num;
    char flag;

if((fin=fopen("fscanf.txt","r"))==NULL)
        {printf("cannot open the file!\n");
        exit (0);}

if((fout=fopen("fprintf.txt","w"))==NULL)
        {printf("cannot open the file!\n");
        exit (0);}

        int i=0;
        while(3==fscanf(fin,"%s%d%c",name,&num,&flag))
        {
        strcmp(stu[i].name,name);
        stu[i].num=num;
        stu[i].flag=flag;
        fprintf(fout,"%s%d%c",stu[i].name,stu[i].num,stu[i].flag);
        printf("%s  %d  %c\n",stu[i].name,stu[i].num,stu[i].flag);
        i++;
        }

}
搜索更多相关主题的帖子: include cannot file 
2013-11-22 15:32
lleon
Rank: 2
等 级:论坛游民
帖 子:25
专家分:43
注 册:2013-10-28
得分:1 
while(3==fscanf(fin,"%s%d%c",name,&num,&flag))
这句有问题,最好不要用fscanf,scanf混输字符数据和数值数据,参考下c primer plus.
2013-11-22 15:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-424013-1-1.html




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

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