Skip to main content
corrected argv index from 2 to 1
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

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[2]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

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[2] 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

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

Source Link
Sean
  • 264
  • 1
  • 3

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[2] 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