diff options
author | Ian C <ianc@noddybox.co.uk> | 2018-07-31 10:46:39 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2018-07-31 10:46:39 +0000 |
commit | 80992ebe6c12cfd9d0d03df6762c2c0f121e6351 (patch) | |
tree | eb67389e274d06da44bd4fc706f0b15652857fab | |
parent | ac3a5fd690bca65e354d3289a7ebb8f489f1dd90 (diff) |
Updated structure to use a union.
-rw-r--r-- | codeword.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -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; } } |