'Cs50 pset5 - program crashing

I finished writing my code for speller. It compiles fine but the only output being printed is "Misspelled words". The words misspelled , words in text, words in dictionary does not get printed. I'm assuming its because the program crashes before then? Here is my code. If only I knew in which function or area my problem lies I might be able to fix it. Also, my hash function is to base hash indexes base on the first two letters of the word.

// Implements a dictionary's functionality

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

#include "dictionary.h"

int dsize = 0;

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

// TODO: Choose number of buckets in hash table
const unsigned int N = 676;

// Hash table
node *table[N];

// Returns true if word is in dictionary, else false
bool check(const char *word)
{
    // TODO
    // hash word
    int hashnumber = hash(word);
    node *cursor = table[hashnumber];
    // traversing linked list at that hash number
    while(cursor != NULL)
    {
        if((strcasecmp(cursor->word, word) == 0))
        {
            return true;
        }
    }
    return false;
}

// Hashes word to a number
unsigned int hash(const char *word)
{
    int hash;
    // TODO: Improve this hash function
    for( int i = 97; i < 123; i ++)
    {
        hash = (i - 97) * 26;
        // check asciivalue both uppercase and lowercase for first letter
         if(word[0] == (char)i || word[0] == (char)(i - 32) )
         {
             for ( int j = 97; j < 122; j++)
              {
                  // check asciivalue both uppercase and lowercase for second letter
                  if(word[1] == (char)j || word[1] == (char)(j - 32))
                  {
                      hash = hash + (j - 97);
                  }

              }
         }

    }


    return hash;
}

// Loads dictionary into memory, returning true if successful, else false
bool load(const char *dictionary)
{
    for( int i = 0; i < N; i++)
    {
        table[i] = NULL;
    }

     FILE *input = fopen(dictionary, "r");

    if (dictionary== NULL)
    {
        return false;
    }

    node *temp;
    char word[LENGTH + 1];
    while((fscanf(input, "%s", word)) != EOF)
    {

       temp = malloc(sizeof(node));
       if(temp == NULL)
       {
           return false;
       }


       strcpy(temp->word, word);
       int hashnumber = hash(word);
       if (table[hashnumber] == NULL)
       {
           table[hashnumber] = temp;
       }
       else
       {
           temp->next = table[hashnumber];
           table[hashnumber] = temp;
       }
       dsize++;
    }
    fclose(input);

return true;
}

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

// Unloads dictionary from memory, returning true if successful, else false
bool unload(void)
{
    // TODO
node *temp;
node *cursor;
    for ( int i = 0; i < N; i++ )
    {
        cursor = table[i];

        while(table[i] != NULL)
        {
            temp = cursor;
            cursor = cursor->next;
            free(temp);
        }
        if(cursor == NULL && i == (N - 1))
        {
            return true;
        }

    }
    return false;
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source