Hot answers tagged

9

It's actually a simple fix. Since it's something that you would either know or not know, here it is. You declare the pointer variable as a global outside of a function, but you malloc space for it inside of main or another function. It's the = malloc(...) part that's killing you here. You can't do that outside of main or another function. If this answers ...


6

Your understanding is correct, but your example has a dangerous flaw if you were to implement it. Look back at your question as a whole. You have two important variables, root and newptr. root is the pointer that actually points to, well, the literal root of the trie. It's critical that you never reassign this pointer. If you do, you'll lose the root of the ...


2

You are confusing things here. First, according to the manual page of realloc Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc() or realloc(). That is obviously not the case here since the member word of the struct node is NOT returned by a call to any of these functions (but new_node itself is). you can't ...


1

Maybe there are a couple things that you haven't grasped yet. First, creating a var and initializing a var are two very different actions. A statement like node *pnode; creates a node var called pnode, a pointer to a node, which stores the address of a node. It is NOT initialized. Pointers are never initialized by default. The statement node *pnode = ...


1

An empty linked list consists only of a NULL pointer, no node. There is no dedicated "head" node, just a "head" pointer pointing to the first node (and if there's none, it's NULL). So you could just use your while loop without any if with special treatment for first node. You forgot its next pointer in that part, but everything is covered by your while. BTW,...


1

Hmmm..... I have some questions for you, in no particular order, but they'll give you something to think about. Why is there a main() in dictionary.c? The provided code is set up so that speller can be compiled directly as you add the needed code in each part. But, for argument, I'll just assume that you want to compile and test dictionary.c directly. ...


1

You are actually returning an address (of a struct), not a struct or an int. By trying to return 1, you are trying to return an int, not an address. Instead of return 1; you could still return new_node; and check whether it is NULL after it is returned. (NULL will still be a valid address, a valid "non-address" in this case.) If this answers your question, ...


1

Basically, everything is a Node. And <title> foo </title> is an element. Read more here: https://www.w3schools.com/html/html_elements.asp and https://www.w3schools.com/jsref/dom_obj_document.asp


1

The definition of struct node is incomplete in struct node itself. To fix this, you need to define struct node like this: typedef struct node{ bool end; struct node* child[27]; }node; Now, child will know what it is. :) You need to do typedef struct name { /* struct */ } name; whenever you have a self-referencing struct.


1

Here's how it works. Your hashtable is an array of node*s (an array of pointers to nodes). Let's say that hashtable[1] is pointing to a node containing the word "apple" at address 0x1001. You have just created a new node for the word "apples" (at address 0x1002) and it hashes to the same bucket (1). So you need to add that node to the linked list. The ...


1

What Zamyla meant, is that you need to inspect the value stored in children[i], and perform some action depending on whether the value is NULL. Basically this equates to an if statement: if (children[i] == NULL) { // children[i] does not point to anything } else { // children[i] points to something } Also the example implies that the children ...


Only top voted, non community-wiki answers of a minimum length are eligible