c语言中不同数据类型之间的相互转化
2015-01-19 19:11
162 查看
1)怎样把带空格的字符串分割成没有空格的字符串(c++)
/*****************************************************************
split a string with space into several small strings without space
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
void split(char* str, double* position)
{
char* words[3];
char* temp;
temp = strtok(str, " ");
int i = 0;
while(temp!=NULL)
{
words[i] = temp;
temp = strtok(NULL, " ");
position[i] = atof(words[i]);
i++;
}
}
int main()
{
char lineBuf[] = "11.12 11.13 11.14";
std::cout << "1" << std::endl;
double position[3];
split(lineBuf, position);
std::cout << "1" << std::endl;
for(int i=0; i<3; i++)
{
// std::cout << words[i] << std::endl;
// position[i] = atof(words[i]);
std::cout << position[i] << std::endl;
}
return 0;
}
/*****************************************************************
split a string with space into several small strings without space
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
void split(char* str, double* position)
{
char* words[3];
char* temp;
temp = strtok(str, " ");
int i = 0;
while(temp!=NULL)
{
words[i] = temp;
temp = strtok(NULL, " ");
position[i] = atof(words[i]);
i++;
}
}
int main()
{
char lineBuf[] = "11.12 11.13 11.14";
std::cout << "1" << std::endl;
double position[3];
split(lineBuf, position);
std::cout << "1" << std::endl;
for(int i=0; i<3; i++)
{
// std::cout << words[i] << std::endl;
// position[i] = atof(words[i]);
std::cout << position[i] << std::endl;
}
return 0;
}
相关文章推荐
- C++中不同数据类型之间的相互转换
- VC++中一些常用的数据类型之间的相互转化
- C语言中不同类型数据之间的赋值
- java 八种基本数据类型之与对应的封装类之间的相互转化
- 不同数据类型以及指针之间的转化
- 字符串和基本数据类型之间的相互转化
- objective-c中不同数据类型之间的相互转换
- 不同Web主机上的Servlet之间数据对象的相互传输
- Android数据类型之间相互转换系统介绍
- VC++中,CString,in,char,等数据类型的相互转化
- 不同Web主机上的Servlet之间数据对象的相互传输
- 使用boost库实现不同数据类型之间的自由转换
- C语言中不同数据类型间混合运算的转换规则
- CopyMemory不同类型数据之间的复制
- java数据类型之间的转换和什么地方要进行强制类型的转化
- VC++中,CString,in,char,等数据类型的相互转化
- Unicode数据类型(与ANSI关系和相互转化)
- 不同Web主机上的Servlet之间数据对象的相互传输
- OO_W2:C#数据类型和C语言有什么不同?
- C#与C++和C语言之间数据类型的对应