I'm trying to create a program that checks for repeated characters within the command line argument's string. The string is suppose to contain only 26 characters, and all characters have to be alphabetical. However, there cannot be any repeated characters within the string, each alphabetical character must appear only once. I figured out the first two sections of the program but I cant figure out how to check for repeated characters. I could really use some help as well as explanations.
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
int main (int argc, string argv[])
{
if (argc != 2)
{
printf("Usage: ./substitution key\n");
return 1;
}
else
{
int len = strlen(argv[1]);
if (len != 26)
{
printf("Key must contain 26 characters.\n");
return 1;
}
else
{
for (int i = 0; i < len; i++)
{
if (!isalpha(argv[1][i]))
{
printf("Usage: ./substitution key\n");
return 1;
}
}
}
}
}
std::map
, please note that this question is tagged C, not C++. Of course, it is possible to implement a map in C too, but that seems like an excessive amount of work for this simple problem. – Crystallo