0

When the program reaches this line of code: if (strcasecmp(seguido->word, word) == 0). It does nothing, it doesn't have an output or continues to the next iteration.

Here are all the functions of speller.

// Implements a dictionary's functionality

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>

#include "dictionary.h"

// Represents a node in a hash table
typedef struct node
{
    char word[LENGTH + 1];
    struct node *next;
}
node;

// Number of buckets in hash table
const unsigned int N = 1;

// Hash table
node *table[N];

char letras[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int numeros[26] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};

FILE *diccionario;

// Check function variables 
node *seguido;

// Amount of words in dictionary
int palabras = 0;
int *cantidad_palabras = &palabras;

// Returns true if word is in dictionary, else false
bool check(const char *word)
{
   char letra = tolower(word[0]);
   for (int position = 0; position < 26; position ++)
   {
       if (letra == letras[position])
       {
           seguido = table[position];
           for (; seguido->next != NULL; seguido = seguido->next)
           {
               if (strcasecmp(seguido->word, word) == 0)  **THIS LINE OF CODE**
               {
                   return true;
               }
               else
               {
                   continue;
               }
           }
           return false;
       }
       else
       {
           continue;
       }
   }
   return false;
}

// Hashes word to a number
unsigned int hash(const char *word)
{
    int index = 0;
    for (int i = 0; i < 26; i++)
    {
        if (tolower(word[0]) == letras[i])
        {
            index = numeros[i];
        }
        else
        {
            continue;
        }
    }
    return index;
}

// Loads dictionary into memory, returning true if successful, else false
bool load(const char *dictionary)
{
    char *words = malloc(sizeof(char) * 46);
    int position = 0;
    diccionario = fopen(dictionary, "r");
    *table = malloc(sizeof(26));
    
    if (diccionario == NULL)
    {
        printf("Could not open file");
        fclose(diccionario);
        return false;
    }
    
    while (fscanf(diccionario, "%s", words) != EOF)
    {
        node *nodo = malloc(sizeof(node));
        strcpy(nodo->word, words);
        position = hash(nodo->word);
        
        if (table[position] == NULL)
        {
            nodo->next = NULL;
            table[position] = nodo;
        }
        if (table[position] != NULL)
        {
            node *temporal = table[position];
            nodo->next = temporal;
            table[position] = nodo;
        }
        cantidad_palabras++;
    }
    fclose(diccionario);
    return true;
}

// Returns number of words in dictionary if loaded, else 0 if not yet loaded
unsigned int size(void)
{
    return *cantidad_palabras;
}

// Unloads dictionary from memory, returning true if successful, else false
bool unload(void)
{
    node *tmp, *sigue;
    for (int position = 0; position < 26; position++)
        {
            tmp = table[position];
            
            while(tmp->next != NULL)
            {
                sigue = tmp->next;
                tmp = sigue;
                sigue = sigue->next;
            }
        }
        return true;
}

You must log in to answer this question.

Browse other questions tagged .