免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4172 | 回复: 3
打印 上一主题 下一主题

fscanf读取文件出问题,请大家帮忙 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-06 10:29 |只看该作者 |倒序浏览
自己写的处理数据文件的小程序,查错查到最后发现fscanf根本不工作,实在找不出问题所在,把程序和数据文件都贴出来,肯请大家帮忙解决!
编译环境:devcpp4.9.9.2

//代码文件:main.cpp
#include <iostream>;
#include <stdlib.h>;
using namespace std;

int main(int argc, char *argv[])
{
    void merge_zone_fcs(char *);
    merge_zone_fcs(argv[1]);
   
    system("AUSE";
    return 0;
}

void merge_zone_fcs(char *well)
{
    FILE* fp_in1, *fp_in2, *fp_out;
        char *fn_in1=new char[20];
        char *fn_in2=new char[20];
        char *fn_out=new char[20];
        char *fcs_name = new char[20];
       
        int microfcs_code=0;
        int zonecode1=0,zonecode2=0;
        double f_top=0;
        double z_top1=0,z_top2=0;
        double depth=0;   //f_top:facies top, z_top: zone top
        bool outofzone=true, zone_is_used=true, fcs_is_used=true;
       
        strcpy(fn_in1, well);
        strcpy(fn_in2, well);
        strcpy(fn_out, well);
        strcat(fn_in1, ".dep";
        strcat(fn_in2, ".facies";
        strcat(fn_out, ".par";
       
        cout<<fn_in1<<endl<<fn_in2<<endl<<fn_out<<endl;
       
    if((fp_in1=fopen(fn_in1,"r")==NULL)
    {
                printf("Cannot Open inputfile %s\n",fn_in1);
                exit(1);
    }

    if((fp_in1=fopen(fn_in2,"r")==NULL)
    {
                printf("Cannot Open inputfile %s\n",fn_in2);
                exit(1);
    }

    if((fp_out=fopen(fn_out,"w")==NULL)
    {
                printf("Cannot Open outputfile %s\n",fn_out);
                exit(1);
    }
    fscanf(fp_in2,"%s%lf",fcs_name,&f_top);
    cout<<fcs_name<<endl<<f_top<<endl;
        fscanf(fp_in1, "%lf%d", &z_top1, &zonecode1);
        cout<<z_top1<<"\t"<<zonecode1<<endl;
       
        fprintf(fp_out,"%12.3lf  -999  -999\n",z_top1);
        fclose(fp_in1);
        fclose(fp_in2);
        fclose(fp_out);
        return;
}

数据文件:a.dep
1230 1
1250 2

a.facies
B 1234
C 1245

论坛徽章:
0
2 [报告]
发表于 2005-07-06 11:25 |只看该作者

fscanf读取文件出问题,请大家帮忙

if((fp_in1=fopen(fn_in2,"r")==NULL)
   {
printf("Cannot Open inputfile %s\n",fn_in2);
exit(1);
   }

应该改成

if((fp_in2=fopen(fn_in2,"r")==NULL)
   {
printf("Cannot Open inputfile %s\n",fn_in2);
exit(1);
   }

论坛徽章:
0
3 [报告]
发表于 2005-07-06 11:28 |只看该作者

fscanf读取文件出问题,请大家帮忙

呵呵,首先文件还没打开啊

论坛徽章:
0
4 [报告]
发表于 2005-07-06 11:34 |只看该作者

fscanf读取文件出问题,请大家帮忙

这几天活忙,脑子太乱了!眼睛也不好使了!还总以为机器跟自己过不去!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP