sscanf、strsep
#include <stdio.h>
#include <string.h> int main()
{
char token[] ="abdzxbcdefgh";
char str[]="3:2:09";
int a1=, a2=, a3=;
int ret; printf("%s\n",token);
char *tokenremain = token;
char *tok1 = strsep(&tokenremain,"cde");
printf("tok1:%s,token:%s\n",tok1,tokenremain);
tok1 = strsep(&tokenremain,"cde");
printf("tok1:%s,token:%s\n",tok1,tokenremain);
printf("%s\n", token );
ret=sscanf( str, "%d:%d:%d", &a1, &a2, &a3 );
printf( "ret=%d,%d:%d:%d\n", ret, a1, a2, a3 ); return ;
}
输出:
abdzxbcdefgh
tok1:ab,token:zxbcdefgh
tok1:zxb,token:defgh
ab
ret=3,3:2:9
注意问题:
1、sscanf返回值,是识别token的个数;
2、strsep会修改被扫描的字符串,会在扫描到的地方设置为'\0'
sscanf、strsep的更多相关文章
- C++中几种输入输出cin、cin.getline()、getline()、sscanf()、sprintf()、gets()等
1.cin和cout cout是输出流对象的名字,cin是输入流对象的名字 ,“<<”是流插入运算符(也可称流插入操作符〉,作用是将需要输出的内容插入到输出流中,默认的输出设备是显示器. ...
- sscanf、sprintf、stringstream常见用法
转载自:https://blog.csdn.net/jllongbell/article/details/79092891 前言: 以前没有接触过stringstream这个类的时候,常用的字符串和数 ...
- 两个神奇的函数~~~sscanf、atoi
sscanf 对你没有看错 多了一个s 这个函数有什么作用呢 功能:读取字符串中的int.double.long.long long .float and so on 类型的数据 譬如说 我现在读入了 ...
- c语言数据读入---sscanf、fscanf
#include <iostream> #include <cstdio> #include <cstring> #include <stdlib.h> ...
- STL学习:STL库vector、string、set、map用法
本文仅介绍了如何使用它们常用的方法. vector 1.可随机访问,可在尾部插入元素:2.内存自动管理:3.头文件#include <vector> 1.创建vector对象 一维: (1 ...
- 二、linux IO 编程---系统调用和POSIX标准和标准IO
2.1 系统调用 2.1.1 概念 所谓系统调用(system call)是指曹错系统提供给用户程序的一组“特殊”接口,用户程序可以通过这组“特殊”接口来获得操作系统内核提供的特殊服务. 应用程序可以 ...
- C/C+小记
1.struct与typedef struct struct Student{int a;int b}stu1; //定义名为Student的结构体,及一个Student变量stu1 struct { ...
- Verilog-1995 VS Verilog-2001
http://www.cnblogs.com/tshell/p/3236476.html 2001年3月IEEE正式批准了Verilog‐2001标准(IEEE1364‐2001),与Verilog‐ ...
- C语言可变参数在宏定义中的应用
在C语言的标准库中,printf.scanf.sscanf.sprintf.sscanf这些标准库的输入输出函数,参数都是可变的.在调试程序时,我们可能希望定义一个参数可变的输出函数来记录日志,那么用 ...
随机推荐
- [Everyday Mathematics]20150102
设 \[ a_1=3,\quad a_{n+1}=\dfrac{1}{2}(a_n^2+1)\quad(n=1,2,\cdots). \] 试求 \[ \vsm{n}\dfrac{1}{1+a_n}. ...
- ExpectationMaximum
2- You may have question marks in your head, especially regarding where the probabilities in the Exp ...
- 10、Android数据存储
课程目标: 掌握Android中数据存储的几种方式 熟练使用PreferenceActivity&PreferenceScreen做专业的Setting功能 熟练使用SQLite3来存储数据 ...
- winform窗体间利用委托传值(一)
前台:在winform窗体Form1放入pictureBox1 后台代码: namespace 点击小图变成大图 { public delegate void ClickDelegateHander( ...
- js特效第九天
offset家族(获取元素尺寸) offsetWidth得到对象的宽度,自己的,与他人无关 offsetWidth = width+border+padding,不包含margin offsetHei ...
- ACM2026
/* 首字母变大写 Problem Description 输入一个英文句子,将每个单词的第一个字母改成大写字母. Input 输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句 ...
- org.springframework.web.filter.DelegatingFilterProxy的理解
org.springframework.web.filter.DelegatingFilterProxy可以将filter交给spring管理. 我们web.xml中配置filter时一般采用下面这种 ...
- DataRow数组 转 datatable
DataTable tmpdt = dt.Clone(); DataRow[] drs = dt.Select("legnbr="+legNbr); ) { tmpdt = drs ...
- 简单OS(ucos超级精简版)——裸调度器【worldsing笔记】
简单原则少ROM,少RAM,任务完成就让出CPU,调度器描述: 1.按最大任务数轮番调度: 2.任务调用延时接口将让出CPU使用权,进入下一个任务调度: 3.用户任务都处于延时或是不使用CPU运行Id ...
- [置顶] Flex中Tree组件无刷新删除节点
在Tree组件中经常要删除某个节点,而删除之后重新刷新加载该Tree组件会影响整个操作效果和效率,因此,无刷新删除就比较好,既删除了节点也没有刷新tree,而使Tree的状态处于删除之前的状态. 无刷 ...