atoi isn't the right solution to the problem. Consider using strtol or strtoul instead.
The problem is that atoi( "111 222 333" ) will return 111 always. What you would
need to do is remove the "111" from the string and then call atoi again, ie,
atoi( " 222 333" ) will now return 222. How to remove the "111" from the string?
Well, look up strtol. It will give you a pointer to the first character in the string
that was not consumed by the previous conversion, ie, strtol on "111 222 333"
would return 111 and also give you a pointer to the space immediately after 111.
You could use that pointer and call strtol again to get 222, etc.
Thanks for the reply first.
Actually there is another problem.
I have to read a string of number from a file,
so I have no idea how long the string will be.
The strtol example here uses char str[] as the string input.
However I have to use string str to ensure that I don't miss anything from every line the file.
How can the strtol example be modified to use string str instead of char str[]?