Skip to main content
2 of 3
added 30 characters in body
UpAndAdam
  • 1.7k
  • 1
  • 4
  • 20

I don't see what would cause you to fail to compile but I see a couple of things you should fix:

  1. type mismatches. You have hash returning an unsigned int, but you don't use unsigned int inside the function or to capture the return value. This is a bug.
  2. You don't NULL Terminate the strings you everytime you use strcpy; this is a bug. Also strongly advise you not to use strcpy, but use strncpy instead.
  3. You have an odd logical issue where you do a bunch of extra work for no benefit. You copy and lower the string in the hash function, which you just copied and lowercased in the check function, and then you still use strcasecmp out in check.. this is very very very silly. You already do the lowercasing in check, and load prior to calling hash so hash has no need to do it again at all. Additionally it means you don't have use strcasecmp and can just use strcmp because you've already converted the words. You're welcome.
  4. in your unload just return i==N no need for if else there
  5. you might want to consider what size should be after unload. yours is definately wrong. You may also consider utilizing size as a check that you are freeing everything and there isn't a bug in your logic somewhere.
  6. why do you need is_loaded? just initialize the count variable to 0, grow it and shrink it as needed, now the size method doesnt have to do any logic. ( which it shouldnt have to do)
  7. lastly why read into buffer only to have to copy it into a node's storage for the word. Why not just read directly into that storage to start with and avoid the copy?

good luck and hope this helps.

UpAndAdam
  • 1.7k
  • 1
  • 4
  • 20