Hey guys I am working on implementing a simple cryptography program called Caesar. I got this program to work perfectly when I was writing a function to handle the cryptography and just declaring the string that I wanted to encrypt and the integer I wanted to move the letters by to encrypt it. maybe you can help me out and tell me what I am doing wrong here. I am just trying to get the user to enter the key into main and then be prompted for the string to encrypt.
I ended up with a segmentation fault.. I have absolutely no idea what I am looking at but when I ran GDP I get this
#0 0x001bd283 in ____strtol_l_internal (nptr=0x0, endptr=0x0, base=10, group=0,
loc=0x3123a0) at strtol_l.c:298..
Anyways here is my code..
int main (int argc, char *argv)
// turn string k into int k
int k = atoi(argv);
k = k % 26;
int i = 0;
// prompt user for string
string word = GetString();
// below here all works fine when I had it as a stand alone function that I
// passed arguments to from main.. should encrypt by "k" letters
while (word[i] != '\0')
if (word[i] >= 'a' && word[i] <= 'z')
word[i] = (word[i] + k - 97) % 26 + 97;
else if (word[i] >= 'A' && word[i] <= 'Z')
word[i] = (word[i] + k - 65) % 26 + 65;
word[i] = '\0';