I am trying to write some code for the Substitution question in Problem Set 2, but I cannot figure out how to reject the case where a user gives a key with repeated letters. My code thus far is as follows:
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, string argv[])
{
int n = strlen(argv[1]);
if (argc == 2 && n == 26)
{
for (int i = 0; i < n; i++)
{
if (!(isalpha(argv[1][i])))
{
printf("Please enter a valid substitution key in the command-line. Your key must only contain 26 letters of the alphabet and they have to be unique.\n");
return 1;
}
}
}
else
{
printf("Please enter a valid substitution key in the command-line. Your key must only contain 26 letters of the alphabet and they have to be unique.\n");
return 1;
}
}
I know that if I were to enter a key with 26 characters, but some repeated, my code would accept it when it should not. I have tried to Google an answer for this, but the solutions I have found are beyond my current comprehension of C. Any ideas on how my code can be tweaked to consider this case will be greatly appreciated!