Rewriting my question, because I've finally figured out which function was returning segfault, but I still don't understand why.
The first part of my code:
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main (int argc, string argv[])
{
//Checks that the key exists.
if (argc!=2)
{
printf("Please enter a valid numerical key after program name.\n");
return 1;
}
//Checks that the key is a non-negative number.
else if (argv[1] < 0 || isdigit(argv[1])
{
printf("Please enter a non-negative numerical key after program name.\n");
return 1;
}
}
I've figured out that it's the isdigit function that keeps returning segfault, and removing it results in the program working perfectly. My question is: why? Must I turn argv[1] into an int before checking that it's a digit or..?