int and argv[][]

I have a nice big problem, that I've happily minimized down to a little problem. Unfortunately, my little problem is the area which I always struggle with, and help would be much appreciated to help me understand (because providing an answer is one thing, explaining why provides learning!).

I have a long number in argv[3], and I need to take out a sequence of digits from the start of this number. (ie. The number is 943209432, and I want just the first three digits, 943, in one int). I'm well aware that argv[] stuff is just a pointer to a string, and by using atoi() or atof() you can convert it to a number.

To take out the first few numbers however I was planning to use argv[3][k], where k gets larger depending on how many numbers I need. Due to my lack of knowledge of pointers and such (or even if this is a pointer now that it's changed) I can't change it into a number.

If that makes no sense, here's my little snippit of code:
1
2
int num100;
num100 = atoi(argv[3][k]);

To me, it seems that that should work, but I am sadly disappointed when errors occur when I compile...

Where have I gone wrong, and why? All I want is a nice little digit between 0 and 9...

Thanks heaps for reading so far, even if you aren't sure of the best way to answer what feels to me like a simple question...
Ah! Would you look at that... You keep trying different things and you eventually find the solution yourself! :-D

Got the solution I was looking for, but still thanks to those that will help me in the future!
You can use the function static_cast in order to cast the variable from Int to String.
This is the syntax

target_Variable = static_cast<target_data_type> (source_variable) ;

In your case it could be

Str1 = static_cast<string>(Int1);

I hope it helps.
Topic archived. No new replies allowed.