The length of the longest possible word is stored in constant LENGTH
, so char str[LENGTH+1];
and fgets (str, sizeof(str), fp)
. Not sure about how to use fgets
(especially how it deals with the line end, whether that's returned as well, and what happens if line end is file end), but it definitely should get the length of the buffer as second argument. Especially not sure how it handles newlines. I read individual characters instead, which may not be your preference, others used get_string
from cs50.h
.
Also, I'm somewhat confused your code works at all. For example, in insert
and search
, you don't handle apostrophes. In load
, for each word you seem to also insert all the endings, so for "cat" you would also insert "at" and "t", which are not in the dictionary.
In check
, you declare lower
of length LENGTH
, while it has to store at most LENGTH+1
characters (remember the null terminator).
In newNode
, the use of calloc
rather than malloc
already means the memory is zeroed, which means false
for booleans and NULL
for pointers (both are actually same as 0
in their value).