免费注册 查看新帖 |

Chinaunix

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

一个关于sscanf的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-06 16:44 |只看该作者 |倒序浏览
环境AIX 4.3
编译器:cc
测试人员:Bluesgone
问题位置:分隔符中间没有数据导致sscanf没有读到后续的数据
时间:2007-11-06
地点:保密
程序用途:保密

fp= fopen("hello.txt","r";
        printf(" open \n";

        fgets(aczLine,1024,fp);
    sscanf( aczLine,"%21[^|]|%21[^|]|%40[^|]|%2[^|]|%20[^|]|%12[^|]|%20[^|]|%20[
^|]|%40[^|]|%6[^|]|%1[^|]|%40[^|]|%20[^|]|%4[^|]|%9[^|]|%3[^|]|%8[^|]|%10[^|\n]"
,
      s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s1;
        printf("  %s<=>%s<=>%s<=>%s<=>%s<=>%s<=>%s<=>%s<=>%s<=>%s<=>%s<=>%s<=>%s
<=>%s<=>%s<=>%s<=>%s<=>%s \n",
       s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s1;
我在使用sscanf解析分隔符为"|"的文件的时候,文件如下:
1111|1122|中国银联|13|412331|张学友|123||广东113|231111||||0|1233440|3|0||
第八个||中间没有数据,
sscanf就没有继续读下面的东西了,打印处理的结果就到231111为止,后面的就没有
打进变量了,请问这是为什么?多谢

[ 本帖最后由 bluesgone 于 2007-11-6 17:20 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-11-06 19:21 |只看该作者
           [           Indicates string data and the normal skip-over-
                       leading-white-space is suppressed.  The left bracket
                       is followed by a set of characters, called the
                       scanset, and a right bracket; the input field is the
                       maximal sequence of input characters consisting
                       entirely of characters in the scanset.  The
                       circumflex (^), when it appears as the first
                       character in the scanset, serves as a complement
                       operator and redefines the scanset as the set of all
                       characters not contained in the remainder of the
                       scanset string.  Construction of the scanset follows
                       certain conventions.  A range of characters may be
                       represented by the construct first-last, enabling
                       [0123456789] to be expressed [0-9].  Using this
                       convention, first must be lexically less than or
                       equal to last; otherwise, the dash stands for itself.
                       The dash also stands for itself when it is the first
                       or the last character in the scanset.  To include the
                       right square bracket as an element of the scanset, it
                       must appear as the first character (possibly preceded
                       by a circumflex) of the scanset, in which case it
                       will not be interpreted syntactically as the closing
                       bracket.  The corresponding argument must point to a
                       character array large enough to hold the data field
                       and the terminating \0, which are added
                       automatically.  At least one character must match for
                       this conversion to succeed.


应该是没有办法的。

论坛徽章:
0
3 [报告]
发表于 2007-11-06 20:47 |只看该作者
原帖由 ivhb 于 2007-11-6 19:21 发表


应该是没有办法的。

So, what I can do is to write a new function for this issue,
sscanf is not powerful enough, it is a pity.

论坛徽章:
0
4 [报告]
发表于 2007-11-07 10:29 |只看该作者
, do it yourself (DIY)

论坛徽章:
0
5 [报告]
发表于 2007-11-08 21:27 |只看该作者
原帖由 iceviewer 于 2007-11-7 10:29 发表
, do it yourself (DIY)

Yup, I'd try a new function, not more flexible than the 'sccanf', but it can work,

that is so great, thank you all the same.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP