strtok() and strtod()
1、strtok(参数1,参数2)按指定的分割符将字符串分割开来
参数1:表示要被分割的字符串的地址;
参数2:表示指定的分割符的地址;
例如:按空格分割“Hello World”
buffer[] = "Hello World";
char *split = " ";
char *data;
data = strtok(buffer,split);
while(data != NULL)
{
printf("data is : %s \n",data);
data = strtok(NULL,split);
}
2、strtod(参数1,参数2)将字符串中的数字转换为double类型的数值
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main()
{
char buffer[] = "2018 Hello 2019 World";
char *endptr; double ret; ret = strtod(buffer, &endptr);
while (*endptr != '\0')
{
if (ret != 0) { printf("data is : %f \n", ret); }
ret = strtod(endptr, &endptr); endptr++; }
getchar();
return 0;
}
strtok() and strtod()的更多相关文章
- C++ 第八课 标准c字符和字符串
atof() 将字符串转换成浮点数 atoi() 将字符串转换成整数 atol() 将字符串转换成长整型数 isalnum() 当字母或数字字符时, 返回真值 isalpha() 当字母字符时, 返回 ...
- 标准c字符和字符串的使用方法
cppreference.com -> Standard C String & Character -> 详解 标准c字符和字符串 atof 语法: #include &l ...
- C语言里字符串的解析
根据给定的字符串,按照一定规则解析字符串,卡住好几次,这次做个笔记,以供参考 函数名称: strtok 函数原型: char *strtok(char *s1, const char *s ...
- hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用
字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...
- strsep和strtok_r替代strtok
char *strtok(char *str, const char *delim) 会修改数据源.外部加锁才线程安全(strtok执行结束再解锁执行另一个strtok循环知道工作完成) 主要是以互斥 ...
- Yocto开发笔记之《Tip-stdlib库函数strtod返回nan错误》(QQ交流群:519230208)
2015.04-imx_v2015.04_3.14.38_6ul_ga+g5d63276 (Jan 04 2016 - 18:07:08) FSL Community BSP : https://co ...
- c语言strtod()函数的用法
函数原型: #include <stdlib.h> double strtod(const char *nptr, char **endptr); C语言及C++中的重要函数. 名称含义 ...
- loadrunner中切割strtok字符串
http://blog.sina.com.cn/s/blog_7ee076050102vamg.html http://www.cnblogs.com/lixiaohui-ambition/archi ...
- strtok&strsep
strtok,strtok_r,strsep--extract tokens from strings Tje strsep() function was introduced as a replac ...
随机推荐
- opencv3.2.0+opencv_contrib-3.2.0+vs2015相关文件的配置
包含目录:E:\opencvcontrib\opencv\sources\build\install\include\opencv E:\opencvcontrib\opencv\sources\bu ...
- python之路正则补充模块
match(从头匹配) 无分组 有分组=====================有括号 ======================================================= ...
- mybatis(五):源码分析 - mapper文件解析流程
- 本地连接服务器的redis,jedisCluster创建问题
1.redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool 查看 ...
- ubuntu中安装和卸载apache2
1. 安装apache2 安装命令: sudo apt-get install apache2 启动/停止/重启apache2: service apache2 start/stop/restart ...
- 记录 shell学习过程(2) read的用法
echo -n "login:"read username #read后面直接使用一个变量用于接收输入的数据 echo -n "password:"read ...
- jqGrid colModel 参数(来自中文手册)
jqGrid colModel 参数 ColModel 是jqGrid里最重要的一个属性,设置表格列的属性. 属性 数据类型 备注 默认值 align string left, center, rig ...
- JSON解析及数据库操作实战篇
代码: JSONObject json = JSONObject.parseObject(ubody);//得到整个json JSONObject AutoTable=json.getJSONObje ...
- Custom LED Keychain, Small And Surefire Gifts
The LED Keychain makes it easy for people to carry their keys with them and carry them with th ...
- (c#)最小绝对差
题目 解