// change values bigger than 26 to one smaller than 26
int key = atoi(argv[1]); 
while (key > 26) 
    key = key - 26;

With respect to the part of my code as above, I faced problems accessing the key before discovering the atoi() function. My question is, why can't I use:

int key = (int) argv[1][0]

to convert the first character of the second string in the terminal input (which I already know is going to be some positive integer), to access the key?

Apologies if my question is slightly convoluted, thanks!

1 Answer 1


Let argv[1] = "1" then

atoi(argv[1]) == 1
(int) argv[1][0] == 49 (ASCII code of '1')
  • Ah, thanks a lot! I didn't understand your response then- until I moved on to subsequent lessons and realised that characters are really integers but with each ASCII character having an assigned integer value.
    – nopeudon
    Jul 27, 2017 at 3:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .