标签:and rto str turn 字符 while main strtok define
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;
}
标签:and rto str turn 字符 while main strtok define
原文地址:https://www.cnblogs.com/zhouzhe-blog/p/10168410.html