summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--codeword.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/codeword.c b/codeword.c
index 4080c7f..0a2be5a 100644
--- a/codeword.c
+++ b/codeword.c
@@ -34,8 +34,11 @@ typedef enum
typedef struct
{
CharacterClass type;
- int number;
- char letter;
+ union
+ {
+ int number;
+ char letter;
+ } data;
} Character;
static void PrepLine(char *p)
@@ -66,7 +69,7 @@ static int ContainsLetter(char c, const Character *chars, int no_chars)
for(f=0; f < no_chars; f++)
{
- if (chars[f].type == eLetter && chars[f].letter == c)
+ if (chars[f].type == eLetter && chars[f].data.letter == c)
{
return 1;
}
@@ -90,7 +93,7 @@ static int CheckLettersAndLength(const char *buff,
for(f=0; f < no_chars; f++)
{
if (chars[f].type == eLetter &&
- (chars[f].letter != buff[f]))
+ (chars[f].data.letter != buff[f]))
{
return 0;
}
@@ -109,7 +112,7 @@ static int CheckNumbers(const char *buff, const Character *chars, int no_chars)
{
if (chars[f].type == eNumber)
{
- int i = chars[f].number - 1;
+ int i = chars[f].data.number - 1;
if (ContainsLetter(buff[f], chars, no_chars))
{
@@ -169,7 +172,7 @@ int CheckAnagram(const char *buff, const Character *chars, int no_chars)
{
if (!used[i] &&
chars[i].type == eLetter &&
- chars[i].letter == buff[f])
+ chars[i].data.letter == buff[f])
{
used[i] = 1;
found = 1;
@@ -251,11 +254,10 @@ int main(int argc, char *argv[])
if (i < 1 || i > 27)
{
chars[f].type = eLetter;
- chars[f].letter =
+ chars[f].data.letter =
tolower((unsigned char)argv[f + 1 + argc_base][0]);
- chars[f].number = 0;
- if (chars[f].letter == '.')
+ if (chars[f].data.letter == '.')
{
chars[f].type = eMissing;
}
@@ -269,8 +271,7 @@ int main(int argc, char *argv[])
}
chars[f].type = eNumber;
- chars[f].number = i;
- chars[f].letter = 0;
+ chars[f].data.number = i;
}
}