I have a question which i have no idea how to do manage.

I need to convert a string in the format like "1 234 567" so i can do some calculations on the indvidual numbers.

What is the best way to do this?

Thanks

Don't know is it the best way but you can do like this. Parse the string until the space (' ') and the number until the space convert to int element of array.

andor: Don't know is it the best way but you can do like this. Parse the string until the space (' ') and the number until the space convert to int element of array.

Thats what i thought i would be able to do but i couldn't get something like that to work. I am probably doing something wrong.

I thought something like below would do the trick but i keep getting cast errors.

while (*string != '\0')
{
for (i = 0; i < strlen(string); i++)
{
converted[i] = atoi((int)string[i]);
}
}

I have a question which i have no idea how to do manage.

I need to convert a string in the format like "1 234 567" so i can do some calculations on the indvidual numbers.

What is the best way to do this?

Thanks

Are you using C++ or C? if you're using C++ then investigate stringstreams, which can be found in the <sstream> library - stringstreams make this sort of thing really, really easy!

In order of preference
strtol() - does conversion and will report numeric overflow / underflow and tell you how much data was processed
sscanf() - like strtol() without the over/under flow
atoi() - pretty useless atoi("0") and atoi("hello") may both return 0