Click to See Complete Forum and Search --> : pointer problems


bsamuels
10-16-2003, 08:19 PM
I'm trying to convert a command line arguement to an int
Why soiesn't this work:

int nval;
nval = atoi(argv[1][1]);

tecknophreak
10-16-2003, 09:26 PM
Originally posted by bsamuels
I'm trying to convert a command line arguement to an int
Why soiesn't this work:

int nval;
nval = atoi(argv[1][1]);

atoi(const char *) is the usage, you're doing atoi(const char) which won't work. if you want to convert a single char just do

nval = argv[1][1] - '0';

or if you want to conver the whole char string then

nval = atoi(argv[1]);

or if you have something like "command -123" then

nval = atoi(&argv[1][1]);

hope that's enough.