void checkspellingfromfile (word_t *words, char *dict)
{
- FILE *fd = fopen (dict, "r");
+ FILE *fd = (dict) ? fopen (dict, "r") : NULL;
if (fd) {
int i;
char str[128] = {0};
{
char **listofwords = NULL;
int nbwords = 0;
- FILE *fd = fopen (dict, "r");
+ FILE *fd = (dict) ? fopen (dict, "r") : NULL;
if (fd) {
char str[128] = {0};
- listofwords = (char **) calloc (NBWORDS + 1, sizeof (char *));
- CHECKALLOC (listofwords);
while (fscanf (fd, "%s", str) > 0) {
- listofwords[nbwords] = strdup (str);
- CHECKALLOC (listofwords[nbwords]);
- nbwords++;
if (nbwords % NBWORDS == 0) {
listofwords = (char **) realloc (listofwords, (nbwords + NBWORDS + 1) * sizeof (char *));
CHECKALLOC (listofwords);
+ memset (listofwords + nbwords, 0, (NBWORDS + 1) * sizeof (char *));
}
+ listofwords[nbwords] = strdup (str);
+ CHECKALLOC (listofwords[nbwords]);
+ nbwords++;
}
fclose (fd);
}
/* test: echo q | scrabble.exe -l it */
/* test: echo q | scrabble.exe -l nl */
/* test: echo q | scrabble.exe -v 5 */
+/* test: echo vlvlvlvlvlvdkjjjjvlvlvlvlvlvdjjjjjvlvlvlvlvlvlvdq | scrabble.exe -l en -d dict/en.dict */
+/* test: echo vlvlvlvlvlvdkjjjjvlvlvlvlvlvdkvjvjvjvjvjvjvdklllvlvxccvq | scrabble.exe -d dict/fr.dict -c */
/* vim: set ts=4 sw=4 et: */