my program compiles but when I input the plain text and run it, I get a segmentation fault. What am I doing wrong?
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main (int argc, string argv[])
{
int key = atoi(argv[1]);
if (argc != 2)
{
printf("Type ./caesar key \n");
return 1;
}
printf("Type your text please: \n");
string text = GetString();
char cipher;
if(isalpha(text))
{
for(int i = 0, n = strlen(text); i < n; i++)
{
if(isupper(text[i]))
{
cipher = (text[i] - 'A') + key;
cipher = cipher % 26;
printf("%c\n", cipher);
}
if(islower(text[i]))
{
cipher = (text[i] - 'a') + key;
cipher = cipher % 26;
printf("%c\n", cipher);
}
}
}
}