【问题标题】:How to scanning this line with fscanf?如何用 fscanf 扫描这一行?
【发布时间】:2018-01-13 18:52:16
【问题描述】:

给定文件只有一行:

001005023000.0028

我怎样才能扫描这个文件(file.txt)并创建这样的结构:

a=001  b=005  c=02  d=3000.00  e=28  

我想用 fscanf 来做,但我的问题是这一行中不存在空格,因此,我不知道我需要在fscanf(..) 中写入的格式是什么

我见过this 还是不明白怎么做。

【问题讨论】:

    标签: scanf


    【解决方案1】:

    我理解正确吗,您是在固定场行中阅读?

    你可以试试

    unsigned int a, b, c, e;
    float d;    
    fscanf(file, "%3u%3u%2u%7f%2u", &a, &b, &c, &d, &e);
    printf("a=%u b=%u c=%u d=%f e=%u", a, b, c, d, e);
    

    【讨论】:

      猜你喜欢
      • 2021-05-12
      • 2018-06-20
      • 2012-07-14
      • 2012-09-15
      • 2016-05-04
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多