1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4
5 int main(){
6 char str[100];
7 //用法一:取指定长度的字符串
8 sscanf("12345","%4s",str);
9 printf("用法一\nstr = %s\n",str);
10
11 //用法二:格式化时间
12 int year,month,day,hour,minute,second;
13 sscanf("2013/02/13 14:55:34","%d/%d/%d %d:%d:%d",&year,&month,&day,&hour,&minute,&second);
14 printf("用法二\ntime = %d-%d-%d %d:%d:%d\n",year,month,day,hour,minute,second);
15
16 //用法三:读入字符串
17 sscanf("12345","%s",str);
18 printf("用法三\nstr = %s\n",str);
19
20 //用法四:%*d 和 %*s 加了星号 (*) 表示跳过此数据不读入. (也就是不把此数据读入参数中)
21 sscanf("12345acc","%*d%s",str);
22 printf("用法四\nstr = %s\n",str);
23
24 //用法五:取到指定字符为止的字符串。如在下例中,取遇到'+'为止字符串。
25 sscanf("12345+acc","%[^+]",str);
26 printf("用法五\nstr = %s\n",str);
27
28 //用法六:取到指定字符集为止的字符串。如在下例中,取遇到小写字母为止的字符串。
29 sscanf("12345+acc121","%[^a-z]",str);
30 printf("用法六\nstr = %s\n",str);
31 return 0;
32 }

本文转自:http://blog.csdn.net/sjf0115/article/details/8579935

最新文章

  1. [原创]jquery+css3打造一款ajax分页插件
  2. Xubuntu VNC Xfce4
  3. 50个令人惊奇的jQuery插件(对话框和表单篇)及免费的响应式bootstrap管理员后台界面主题 - Charisma
  4. TTFB-首字节时间简介
  5. OPENGL学习之路(0)--安装
  6. Python框架、库以及软件资源汇总
  7. puppet安装
  8. 电子科大POJ &quot;3*3矩阵的乘法&quot;
  9. IOS拷贝文件到沙盒
  10. webservice整合spring
  11. &lt;libxml2/tree.h&gt; file not found
  12. 一个web应用的诞生(6)--用户账户
  13. encodeURI()和encodeURIComponent()
  14. 【一天一道LeetCode】#96. Unique Binary Search Trees
  15. 高性能网络IO模型
  16. SVN 使用方法
  17. final和static关键字
  18. FindBugs-IDEA插件的使用
  19. NoClassDefFoundError与ClassNotFoundException
  20. Confluence 6 垃圾收集性能问题

热门文章

  1. SQLSERVER 修改数据实例的排序规则
  2. python-列表包字典-根据字典的某一个键的值来进行排序
  3. 相对论中的光速c不变,这么讲!你总能理解了吧!
  4. Wi-Fi IoT套件连PCF8563实现电子钟功能
  5. MySQL新特性MTS
  6. hive搜索报错
  7. __del__ PyPy和CPython的不同点 动态编译(注意不是解释) 析构函数被调用的次数
  8. 【C++小知识】#define、enum、const的含义与用法
  9. Language Guide (proto3) | proto3 语言指南(十三)JSON映射
  10. cnpm安装依赖时报Error: Cannot find module &#39;core-js/modules/es6.regexp.constructor&#39;