0

Post before suggests that there was some problem with

I malloc dict_word now. However, it still is not loading regarding to vangrid. Coud you possibly share your thoughts?

http://pastebin.com/BhvrB9Ky enter image description here

1 Answer 1

1

I think the problem could be with your dict_word, you have a pointer to a char (char*) and you're pointing it at a block of allocated memory which is also the size of a pointer to a char (the block of memory would really want to be size char, not char*). I think you're then tying to store a whole string into that pointer. Even if you change your malloc size to char, it will only be space for one character.

A way around this is for you is to either dynamically allocate the memory for each character read from file until you reach the end of a word. Or as we know a word cannot be longer than LENGTH (45 characters as specified in dictionary.h) you can allocate memory for each word as char * LENGTH+1 (the +1 for the null terminator). In this case the memory isn't being allocated dynamically and therefore you could actually declare it as an array on the stack.

1
  • Thank you, I will try to malloc for 46 bytes. :)
    – Ichi
    Jun 19, 2016 at 11:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .