I think the problem with is the load() function, here is my code:

bool load(const char *dictionary)
char *s = malloc(LENGTH + 1);
FILE *f = fopen(dictionary, "r");
if (f == NULL)
    return false;
while (fscanf(f, "%s", s) != EOF)
    node *n = malloc(sizeof(node));
    if (n == NULL)
        return false;
    strcpy(n -> word, s);
    int x = hash(n -> word);
    n -> next = table[x];
    table[x] = n;
    fclose (f);
return true;

help50 is asking me to look at this line - while (fscanf(f, "%s", s) != EOF)

This is the complete message - Looks like you're trying to access 4 bytes of memory that isn't yours? Did you try to index into an array beyond its bounds? I have no idea what it means by the memory doesn't 'belongs' to me! I have used malloc() to assign memory to it! Can someone please explain what went wrong??


Closing the dictionary file after the first word is processed is indicated.

From man fclose (emphasis added):

Return Value

Upon successful completion 0 is returned. Otherwise, EOF is returned and errno is set to indicate the error. In either case any further access (including another call to fclose()) to the stream results in undefined behavior.

| improve this answer | |
  • Oh! i don't know how i missed that! Thank You.... – Musical_Ant May 4 at 7:08

You must log in to answer this question.

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