diff options
-rw-r--r-- | codeword.c | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -24,9 +24,16 @@ #include <errno.h> #include <ctype.h> +typedef enum +{ + eLetter, + eNumber, + eMissing +} CharacterClass; + typedef struct { - int is_letter; + CharacterClass type; int number; char letter; } Character; @@ -59,7 +66,7 @@ static int ContainsLetter(char c, const Character *chars, int no_chars) for(f=0; f < no_chars; f++) { - if (chars[f].is_letter && chars[f].letter == c) + if (chars[f].type == eLetter && chars[f].letter == c) { return 1; } @@ -82,7 +89,7 @@ static int CheckLettersAndLength(const char *buff, for(f=0; f < no_chars; f++) { - if (chars[f].is_letter && + if (chars[f].type == eLetter && (chars[f].letter != buff[f])) { return 0; @@ -100,7 +107,7 @@ static int CheckNumbers(const char *buff, const Character *chars, int no_chars) for(f = 0; f < no_chars; f++) { - if (!chars[f].is_letter) + if (chars[f].type == eNumber) { int i = chars[f].number - 1; @@ -139,7 +146,8 @@ int main(int argc, char *argv[]) if (argc < 3) { - fprintf(stderr, "usage: %s wordlist <letter or number> ...\n", argv[0]); + fprintf(stderr, "usage: %s wordlist <letter, number or period> ...\n", + argv[0]); exit(EXIT_FAILURE); } @@ -159,13 +167,18 @@ int main(int argc, char *argv[]) if (i < 1 || i > 27) { - chars[f].is_letter = 1; + chars[f].type = eLetter; chars[f].letter = tolower((unsigned char)argv[f+2][0]); chars[f].number = 0; + + if (chars[f].letter == '.') + { + chars[f].type = eMissing; + } } else { - chars[f].is_letter = 0; + chars[f].type = eNumber; chars[f].number = i; chars[f].letter = 0; } |