int main(int argc, string argv[])
{
string keyword = argv[1];
if (argc != 2)
{
printf("Please reenter with a cipher keyword);
return 1;
}
if (isalpha(keyword))
{
printf("Keyword is %s\n", keyword);
}
else
{
printf("Keyword must be alphabetical\n");
return 1;
}
1 Answer
First issue is that you blindly get argv[1]
before actually checking the number of arguments. The segfault, however, comes from the fact you are passing a string to isalpha
, whose argument is actually a char
(see cs50 reference).