I am trying to solve the substitution problem on CS50 course. After I finished with it, I tried to compile but it does not work correctly. It always returns the ./sustitiuion key part even though I give true key. Can you see what is wrong?
The part while I check the key seems incorrect, and I am nearly sure that there shouldn't be problem because I checked on the Internet for the same part and it is nearly the same.
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Usage: ./substituion key \n");
return 1;
}
//validate the key!
string key = argv[1];
for (int i = 0; i < strlen(key); i++)
{
if (!isalpha(key[i]))
{
printf("Usage: ./substitution key\n");
}
}
for (int j = 0; j < strlen(key); j++)
{
for (int k = 0; k < strlen(key); k++)
{
if (toupper(key[j]) == toupper(key[k]))
{
printf("Usage: ./substitution key \n");
return 1;
}
}
}
if (strlen(argv[1]) != 26)
{
printf("Usage: ./substituion key \n");
return 1;
}
Why are this course's problems so hard?