String into float Array

Hello everybody,

I have a formatted string like:

((floatnumber, floatnumber)(floatnumber, floatnumber)(floatnumber, floatnumber))

And I want to write the floatnumbers into two float arrays. I wrote a function with searches for a beginner character and an end character. The character within this boundarys are converted to the string array.

I would be glad if someone could review my code, if this is a proper way to do it. Further advices for programming style(Var names etc.) are welcome as well.

Regards

yeti

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <sstream>

void mystrsplit(float *array, const std::string input, const char cBegin, const char cEnd);

int main(int argc, char* argv[]){
	std::string a="((1.1,1.2)(2.1,2.2)(3.1,3.2))";
	float p[3];
	float o[3];
	mystrsplit(&p[0], a,'(',',');
	mystrsplit(&o[0], a,',',')');
	for(int ip=0;ip<3;ip++)
	{
		std::cout<<ip<<": "<<p[ip]<<" : "<<o[ip]<<std::endl;
	}
	std::cin.get();
return 0;
}

void mystrsplit(float *array, const std::string input, const char cBegin, const char cEnd)
{
	std::stringstream sstr;
	unsigned int beginNumber=1;
	unsigned int endNumber=1;
	unsigned int index=0;
	while(endNumber!=std::string::npos)
	{
		beginNumber=input.find(cBegin,beginNumber);
		endNumber=input.find(cEnd,beginNumber);
		if(endNumber!=std::string::npos)
		{
			for(unsigned int j=1;j<(endNumber-beginNumber);j++)
			{
				sstr<<input[beginNumber+j];
			}
			sstr>>array[index];//=sNumber;
			sstr.str(std::string());
			sstr.clear();
			beginNumber=endNumber;
			index++;
		}
	}
}
Is there a problem with my Question? I get no answers.

Would be glad for help, thanks!
Topic archived. No new replies allowed.