I'm trying to write a program that Caesar ciphers the string given by the user, but every time I try running it the error "Segmentation Fault" pops up. What am I doing wrong?
int main(int argc, string argv[])
{
if (argc != 2)
{
return 1;
}
int key = atoi(argv[1]);
printf("Plaintext: ");
string Ptext = get_string();
string cipher = 0;
if(Ptext != NULL)
{
for(int i = 0, n = strlen(Ptext); i < n; i++)
{
if(isalpha(i))
{
if(isupper(i))
{
cipher += toupper(((i + key) % 26));
}
else
{
cipher += tolower(((i + key) % 26));
}
}
cipher += i;
}
printf("Ciphertext: %s", cipher);
printf("\n");
}
}