summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2018-07-19 08:26:56 +0000
committerIan C <ianc@noddybox.co.uk>2018-07-19 08:26:56 +0000
commit71cfb7fbe93b80d52176650b4e67df3140c134cc (patch)
tree5bd604e046b02c65a214c3ae048dc78668446548
parent8d8c8e1fd16884a7905657fc7d4cf5224966d7b9 (diff)
Added missing letters mode.
-rw-r--r--codeword.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/codeword.c b/codeword.c
index 38f8c87..fc68f3a 100644
--- a/codeword.c
+++ b/codeword.c
@@ -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;
}