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

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...