15,961,188 members
See more:
I need to read two integers from the command line via argc and *argv[] for my homework. How can I achieve this? As you know, the parameters are strings and I have to convert them to integers in order to use it. Thank you.
Posted
Updated 19-Jan-11 14:16pm
v2
Yusuf 19-Jan-11 21:05pm
Why is this down-voted. OP clearly stated he need help with his HW, not do my HW.

## Solution 1

function atoi[^] will convert string to integer.

Nish Nishant 19-Jan-11 20:18pm
HimanshuJoshi 19-Jan-11 20:19pm
Thanks Nish.
Sergey Alexandrovich Kryukov 19-Jan-11 20:35pm
A 5.
HimanshuJoshi 19-Jan-11 20:39pm
Thanks SA

## Solution 3

atoi is perfect in this case, however there are other functions which you may find usefull in the future for similar tasks

strtol - "string to long"
strtoul - "string to unsigned long"
strtod - "string to double"

These functions take a char **_EndPtr parameter which on return holds the position that the new string pointer after the number processed. This is helpful if you have a number in a string.

strtol and strtoul take the radix as an additional parameter to specify the number base of the string so you can convert binary, octal, decimal, hexadecimal or any other base string to its integer equivalent

check out their pages on MSDN: atoi[^], strtol[^], stroul[^], strtod[^]