sscanf的用法
sscanf也太好用了8我竟然一直都不知道qaq
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std; const int N=;
char s[N],s1[N],s2[N],s3[N],ch[N];
int x; int main()
{
//freopen("a.in","r",stdin); //转换类型
sscanf("123456aaa","%s",s);
printf("s = %s\n",s); sscanf("","%d",&x);
printf("x = %d\n",x); sscanf("","%4d",&x);//最多取前4位
printf("x = %d\n",x); sscanf("123456aaa","%4s",s);//最多取前4位
printf("s = %s\n",s); sscanf("123456abc","%[^b]",s);//遇到b则截止
printf("s = %s\n",s); sscanf("123456abc abc","%[^ ]",s);//遇到空格则截止
printf("s = %s\n",s); sscanf("123456abcabcAabc","%[^A-Z]",s);//遇到大写字母则截止
printf("s = %s\n",s); sscanf("word1 word2 word3 word4", "%*s%s",s);//过滤掉第一个匹配到的%s,保留第二个
printf("s = %s\n",s); sscanf("123456abc abc","%[1-9a-z]",s);//只取1-9 a-z的字符
printf("s = %s\n",s); gets(ch);
sscanf(ch," %s = %s + %s",s1,s2,s3);//方便处理输入格式
printf("s1=%s s2=%s s3=%s\n",s1,s2,s3); return ;
}
a.in
word1 = word2 + word3
输出
s = 123456aaa
x =
x =
s =
s = 123456a
s = 123456abc
s = 123456abcabc
s = word2
s = 123456abc
s1=word1 s2=word2 s3=word3
sscanf的用法的更多相关文章
- C语言函数sscanf()的用法
从文件读取数据是一件很麻烦的事,所幸有sscanf()函数. C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( st ...
- sscanf的用法(转)
队长做上海邀请赛的I题时遇到一个棘手的问题,字符串的处理很麻烦,按传统的gets全部读入的话还要做N多处理,太浪费时间. 回来之后搜了一下sscanf的用法发现可以很好的解决这一类问题,各种百度,转来 ...
- sscanf高级用法级正则表达式
sscanf高级用法级正则表达式 摘自:https://www.cnblogs.com/bluestorm/p/6864540.html sscanf与scanf类似,都是用于输入的,只是后者以屏幕 ...
- C语言函数sscanf()的用法(转)
转自:http://www.cnblogs.com/lyq105/archive/2009/11/28/1612677.html C语言函数sscanf()的用法 sscanf() - 从一个字符串中 ...
- C语言函数sscanf()的用法-从字符串中读取与指定格式相符的数据(转)
C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var ...
- C语言函数sscanf()的用法-(转自Walter L)
在我的学习过程中,从文件读取数据是一件很麻烦的事,所幸有sscanf()函数. C语言函数sscanf()的用法sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int ss ...
- sscanf函数用法详解
sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( string str, string fmt, mixed var1, mixed var2 ... ...
- C语言中 sscanf 的用法
名称: sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( string str, string fmt, mixed var1, mixed var2 ...
- sscanf()的用法
头文件 #include 定义函数 int sscanf (const char *str,const char * format,........); 函数说明 sscanf ...
- 【转】sscanf函数用法实例
sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( string str, string fmt, mixed var1, mixed var2 . ...
随机推荐
- 系统常量对话框QT实现
1.运行结果: 2.代码 main.cpp #include "constantdiag.h" #include <QtWidgets/QApplication> in ...
- SVM之对偶问题
SVM之问题形式化 >>>SVM之对偶问题 SVM之核函数 SVM之解决线性不可分 写在SVM之前——凸优化与对偶问题 前一篇SVM之问题形式化中将最大间隔分类器形式化为以下优化问题 ...
- 在c++中调用exe程序进行操作
#include <Windows.h> #include <iostream> #include <direct.h> #define picNum 228 us ...
- shit antd & Merry Christmas bug
shit antd & Merry Christmas bug https://github.com/ant-design/ant-design/issues/13098 antd 玩大了? ...
- EJB介绍
EJB定义: 被称为java企业bean,服务器端组件,核心应用是部署分布式应用程序.用它部署的系统不限定平台.实际上EJB是一种产品,描述了应用组件要解决的标准. 标准: 可扩展 (Scalable ...
- (二)MySQL学习笔记
1.视图 视图是一系列select语句返回的可视化结果集,是一张虚拟表.更多介绍请查看http://tool.oschina.net/apidocs/apidoc?api=mysql-5.1-zh 视 ...
- BFS的小结
写这类搜索题.首先感觉要有个框架.比如我的框架对于BFS来说(对于DFS,我想有两个一个是递归版一个是栈版).这里是BFS小结.所以介绍一下BFS.我的框架.(也是搜集了网上许多神人的作品.) 1:节 ...
- X day2
题目 官方题解 T1: 我们可以把问题化简为$a\times b \times c \leq n $中的有序$(a,b,c)$有多少组.分三种情况考虑 当$a=b=c$时,答案十分好统计 当$a< ...
- JavaScript去除数组中的重复值
用原型函数(prototype)可以定义一些很方便的自定义函数,实现各种自定义功能. Javascript 中的原型函数(prototype)的工作原理,在 javascript 中每次声明新函数的过 ...
- HDU 4549 矩阵快速幂+快速幂+欧拉函数
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...