My load()
function updates a global array initialized to NULL
. check()
thereafter converts word
to lowercase and stores it in a buffer. Most elements in the array store NULL
, however sometimes a real memory address is found and the condition for the while
loop, as well as the if
condition succeeds and true;
gets returned.
The relevant two functions are below together with global variables and arrays.
// Global variables and arrays for simple access
char buffer[LENGTH+1]; // Declares the buffer to store one line or one word in total
int wordcount = 0;
int hash_index = 0;
node* head_array[HASHTABLE_SIZE] = {NULL}; // Stores pointer to node datatype
node* head_node; // Will always be the most recent node, and first in the list
FILE* dict_file;
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
bool load(const char* dictionary)
{
// Open dictionary file, and error-check
dict_file = fopen(dictionary, "r");
if (dict_file == NULL)
return false;
while (fgets(buffer, LENGTH+1, dict_file) != NULL) {
*/ REDACTED TO COMPLY WITH ACADEMIC HONESTY /*
return true;
}
Some messing around with gdb says that head_array
contains:
{0x0, 0x0, 0xebd750, 0x0, 0x0, 0x0, 0xebef10, 0x0, 0x0, 0x0, 0xebe510,
0x0, 0x0, 0x0, 0xebed10, 0x0, 0x0, 0x0, 0xebee50, 0x0, 0x0, 0x0, 0xebded0,
0x0, 0x0, 0x0, 0xebe890, 0x0, 0x0, 0x0, 0xebeb50, 0x0, 0x0, 0x0, 0xebe550,
0x0, 0x0, 0x0, 0xebe650, 0x0, 0x0, 0x0, 0xebebd0, 0x0, 0x0, 0x0, 0xebecd0,
0x0, 0x0, 0x0, 0xebe850, 0x0, 0x0, 0x0, 0xebed50, 0x0, 0x0, 0x0, 0xebeed0,
0x0, 0x0, 0x0, 0xebe110, 0x0, 0x0, 0x0, 0xebee90, 0x0, 0x0, 0x0, 0xebec10,
0x0, 0x0, 0x0, 0xebee10, 0x0, 0x0, 0x0, 0xebe410, 0x0, 0x0, 0x0, 0xebe1d0,
0x0, 0x0, 0x0, 0xebe610, 0x0, 0x0, 0x0, 0xebe010, 0xbd1a90, 0x0, 0x0,
0xebedd0, 0x0, 0x0, 0x0, 0xebec50, 0x0}