I have a homework assignment for a c class I am in currently, the assignment is to write a simple spell checker. I am having a bit of trouble understanding how to write a trie in c. A trie would be composed of nodes, which contain the following I believe:

1. char value (value of the node)
2. boolean isroot (is this the root node)
3. boolean endsword (is this the end of a word)
optionally
4. Node *nextnode ( a pointer to the next node if one exists).

What I am confused on, is how this should be written as an ADT in c. I have found a few samples online based in Java, but they tend to have too many features.

I would also like to add they need a 2nd pointer to the next sibling.

So I have been working a bit further but seem to have something wrong in my code. The header file for each node is this "node.h"

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>

typedef struct node { 
	char value;
	bool isroot;
	bool isend;
	struct node* sibling;
	struct node* child; 
}

The code for my test of the node structure is this "node.c"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include "node.h"

int main(void){
	return 0;
}

The makefile reads as such:

CC=gcc
CFLAGS=-Wall -g

eread:	node.o
	$(CC) $(CFLAGS) -o $@ node.o

node.c: node.h

And finally the error message is this

$ make
gcc -Wall -g   -c -o node.o node.c
node.c:6: error: syntax error at end of input
make: *** [node.o] Error 1

Any ideas what is going on here?

Missing ; at end of typedef.

so new header file is this:

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>

typedef; struct node { 
	char value;
	bool isroot;
	bool isend;
	struct node* sibling;
	struct node* child; 
}

And the error message then becomes:

$ make
gcc -Wall -g   -c -o node.o node.c
In file included from node.c:6:
node.h:8: warning: useless storage class specifier in empty declaration
node.h:8: warning: empty declaration
node.c:8: error: two or more data types in declaration specifiers
node.c:8: warning: return type of ‘main’ is not ‘int’
node.c: In function ‘main’:
node.c:9: error: incompatible types in return
node.c:10: warning: control reaches end of non-void function
make: *** [node.o] Error 1

The warnings are not as troubling to me as the errors, though I am pretty sure that whatever is causing them is related.

Funny:

typedef struct node { 
	char value;
	bool isroot;
	bool isend;
	struct node* sibling;
	struct node* child; 
}; //<== if semicolon goes here, it's much more reasonable
typedef struct node { 
	char value;
	bool isroot;
	bool isend;
	struct node* sibling;
	struct node* child; 
};

He meant there.

Wow... now I feel... dumb :) . Anyway brings me to a final warning

$ make
gcc -Wall -g   -c -o node.o node.c
In file included from node.c:6:
node.h:14: warning: useless storage class specifier in empty declaration
gcc -Wall -g -o eread node.o

What exactly does this mean?

Do you know why do you use typedef?
It's syntax should be:

typedef some huge type A_DEF;

And the code you wrote has no use from typedef since you haven't specified name that will replace that struct.

>What exactly does this mean?

typedef struct node { 
	char value;
	bool isroot;
	bool isend;
	struct node* sibling;
	struct node* child; 
} [B]aliasname[/B];

Where aliasname is any identifier you want to substitute struct node for.

No clue, I was following a guide regarding linked lists online. Again I am trying to create a Trie as an abstract data type, so would this beneficial to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.