Every time I have used atoi it has returned zero.
Here's some example code
int key = atoi(argv[1]);
and
int atoi(message);
Where am I going wrong?
If this is for example for Caesar cipher and you're running ./caesar 2
then key should indeed be set to an integer of 2
as argv[0]
is the program name and argv[1]
is the string 2
.
But int atoi(message);
first doesn't set the return value of atoi to anything, no variable, and also if message is a string of chars, which from it's name it seems to be, then calling atoi on it will indeed return 0. Although you're not saving that anywhere yet.
Hope that helps Sean
./caesar
, and forget to check that argc>1, then you'll get a seg fault.