免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 C/C++ sscanf
最近访问板块 发新帖
查看: 1527 | 回复: 6
打印 上一主题 下一主题

sscanf [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-09 15:52 |只看该作者 |倒序浏览
strcpy(buf,"[23423][456][354]");
   sscanf(buf,"[%s/][%s/][%s]",buf4,buf2,buf3);

这样写为什么不能把[]种数据提取出来,把[]都换成空格就行为什么啊?

论坛徽章:
0
2 [报告]
发表于 2007-02-09 15:56 |只看该作者
%s 后的那个 / 是什么意思?

请看 sscanf 的手册,几乎是应有尽有:

  1.      Each successive pointer argument must correspond properly with each suc-
  2.      cessive conversion specifier (but see ``suppression'' below).  All con-
  3.      versions are introduced by the % (percent sign) character.  The format
  4.      string may also contain other characters.  Whitespace (such as blanks,
  5.      tabs, or newlines) in the format string match any amount of whitespace,
  6.      including none, in the input.  Everything else matches only itself.
  7.      Scanning stops when an input character does not match such a format char-
  8.      acter.  Scanning also stops when an input conversion cannot be made (see
  9.      below).
复制代码

论坛徽章:
0
3 [报告]
发表于 2007-02-09 15:59 |只看该作者
sscanf(buf,"[%s][%s][%s]",buf4,buf2,buf3);
应该是这样的,我以为要转义呢加上的!

论坛徽章:
0
4 [报告]
发表于 2007-02-09 16:02 |只看该作者
--

转义用的是 backward slash,\,而 forward slash / 不会被理睬

--

论坛徽章:
0
5 [报告]
发表于 2007-02-09 16:03 |只看该作者
能解释就帮我解释一下,英文看的明白肯定就man而不是来这里提问了,谢谢!

论坛徽章:
0
6 [报告]
发表于 2007-02-09 16:08 |只看该作者
--

我翻译不好,就简单地说一下:*scanf 系列函数,遇到格式字符串中的异常情况,比如遇到不匹配处,或者无法正常转换,等等,会退出来

空格 制表符 换行符 等等,不强求数量对应。会直接跳过去

英语不好,会是一个很大的瓶颈

--
liujianfeng1984 该用户已被删除
7 [报告]
发表于 2007-02-09 16:32 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP