sscanf的最基础用法(非原创)
2024-09-02 07:30:25
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
最新文章
- [原创]jquery+css3打造一款ajax分页插件
- Xubuntu VNC Xfce4
- 50个令人惊奇的jQuery插件(对话框和表单篇)及免费的响应式bootstrap管理员后台界面主题 - Charisma
- TTFB-首字节时间简介
- OPENGL学习之路(0)--安装
- Python框架、库以及软件资源汇总
- puppet安装
- 电子科大POJ ";3*3矩阵的乘法";
- IOS拷贝文件到沙盒
- webservice整合spring
- <;libxml2/tree.h>; file not found
- 一个web应用的诞生(6)--用户账户
- encodeURI()和encodeURIComponent()
- 【一天一道LeetCode】#96. Unique Binary Search Trees
- 高性能网络IO模型
- SVN 使用方法
- final和static关键字
- FindBugs-IDEA插件的使用
- NoClassDefFoundError与ClassNotFoundException
- Confluence 6 垃圾收集性能问题
热门文章
- SQLSERVER 修改数据实例的排序规则
- python-列表包字典-根据字典的某一个键的值来进行排序
- 相对论中的光速c不变,这么讲!你总能理解了吧!
- Wi-Fi IoT套件连PCF8563实现电子钟功能
- MySQL新特性MTS
- hive搜索报错
- __del__ PyPy和CPython的不同点 动态编译(注意不是解释) 析构函数被调用的次数
- 【C++小知识】#define、enum、const的含义与用法
- Language Guide (proto3) | proto3 语言指南(十三)JSON映射
- cnpm安装依赖时报Error: Cannot find module &#39;core-js/modules/es6.regexp.constructor&#39;