Browse Source

dictionary file location

master
alistair 4 years ago
parent
commit
2dab9d5895
  1. 1
      Makefile
  2. 25
      main.c

1
Makefile

@ -8,6 +8,7 @@ debug: main.c @@ -8,6 +8,7 @@ debug: main.c
install: default
cp banagram /usr/bin/banagram
cp -n words /usr/share/dict/banawords
uninstall:
rm /usr/bin/banagram

25
main.c

@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
#include <ctype.h>
#include <stdbool.h>
#define DICTFILE "/usr/share/dict/banawords"
/*
* Copyright 2020 Alistair Michael
*
@ -60,10 +62,23 @@ int *count_char(char *word) { @@ -60,10 +62,23 @@ int *count_char(char *word) {
}
return counts;
}
FILE *open_dict_file(char *filename) {
FILE *wfile = fopen(filename, "r");
if (!wfile) {
fprintf(stderr, "Unable to open dict\n");
exit(1);
}
return wfile;
}
// @param allowed: additional characters allowed in anagram match,
// set to NULL to allow matching any set of characters.
int get_minimum_match(char *word, int added, char *allowed) {
FILE *wfile = fopen("words", "r");
FILE* wfile = open_dict_file(DICTFILE);
char line[LINELENGTH];
int err;
int len = strlen(word);
@ -97,6 +112,10 @@ int get_minimum_match(char *word, int added, char *allowed) { @@ -97,6 +112,10 @@ int get_minimum_match(char *word, int added, char *allowed) {
if (allowed) {
max_letter_counts = count_char(allowed);
if (!max_letter_counts) {
return 1;
}
for (int i = 0; i < 26; i++) {
max_letter_counts[i] += orig_word_letter_counts[i];
}
@ -150,9 +169,11 @@ int get_minimum_match(char *word, int added, char *allowed) { @@ -150,9 +169,11 @@ int get_minimum_match(char *word, int added, char *allowed) {
return 0;
}
int get_exact_anag(char *word) {
FILE *wfile = fopen("words", "r");
make_lowercase(word);
FILE* wfile = open_dict_file(DICTFILE);
char line[LINELENGTH];
int err;

Loading…
Cancel
Save