One last issue with my Substitution code. I keep getting the following error when I run check50: :( handles multiple duplicate characters in key timed out while waiting for program to exit
My solution for the error code if a user inputs duplicate chars was to convert the key to all lowercase, and then to check whether the sum of all those letters' ASCII values was NOT 2847, which should be the sum of a through z. This worked, and threw the error code when I tried a few keys with duplicate chars. But not when check50 runs.
I should add that when I run only this part of my code as its own program, it works correctly. I returns the error message if i input keys with duplicates, and it doesn't return an error if I input a valid key.
Any thoughts?
Here's the code:
#include <cs50.h> #include <stdio.h> #include <ctype.h> #include <string.h>
int main(int argc, string argv[]) {
int lenkey = strlen(argv[1]);
int sumlower = 0;
for (int j = 0; j < lenkey; j++)
{
if (isupper(argv[1][j]))
{
argv[1][j] += 32;
}
sumlower += argv[1][j];
}
if (sumlower != 2847)
{
printf("Key must not use any letter more than once\n");
return 1;
}
// Don't need this. Just to verify.
else
{
printf("Valid key. First letter: %c\n", argv[1][0]);
return 0;
}
}