博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sscanf的最基础用法(非原创)
阅读量:4599 次
发布时间:2019-06-09

本文共 1075 字,大约阅读时间需要 3 分钟。

1 #include
2 #include
3 #include
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

转载于:https://www.cnblogs.com/zmin/p/7620460.html

你可能感兴趣的文章
Ubuntu16.04下配置ssh免密登录
查看>>
实验二 2
查看>>
will-change属性
查看>>
android学习笔记54——ContentProvider
查看>>
Unity3d android开发之触摸操作识别-双击,滑动去噪处理
查看>>
Custom view * is not using the 2- or 3-argument View constructors; XML attributes will not work
查看>>
模型选择准则
查看>>
安卓动态增加按钮
查看>>
iOS7程序后台运行
查看>>
maven+testng+reportng的pom设置
查看>>
IT telephone interview
查看>>
gitlab安装配置
查看>>
ps载入画笔
查看>>
悲怆:IT人的一声叹息->一个程序员的自白[转帖]
查看>>
[SpringMVC]自定义注解实现控制器访问次数限制
查看>>
日记(序)
查看>>
A == B ?
查看>>
洛谷P3763 [Tjoi2017]DNA 【后缀数组】
查看>>
GSM模块_STM32实现GPRS与服务器数据传输经验总结
查看>>
5.Python进阶_循环设计
查看>>