I'm taking a intro CS course (CS50x) and came across a slight problem.
Why is this C code producing a segmentation fault when there is only argc[1]
?
It should print the statement. Why won't it print the error?
Thanks in advance!
int main(int argc, string argv[])
{
//HOUSEKEEPING
//Get/Validate Key
string key = argv[1];
int finalKey = atoi(key) % 26;
while (argc != 2)
{
for (int i = 0; i < strlen(key); i++)
if (!isdigit(key[i]))
{
printf("Usage: ./caesar key\n");
return 1;
}
else
{
printf("Usage: ./caesar key\n");
return 1;
}
//...