| | |
Trie's in C
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 15
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: Oct 2008
Posts: 15
Reputation:
Solved Threads: 1
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"
The code for my test of the node structure is this "node.c"
The makefile reads as such:
And finally the error message is this
Any ideas what is going on here?
c Syntax (Toggle Plain Text)
#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"
c Syntax (Toggle Plain Text)
#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:
C Syntax (Toggle Plain Text)
CC=gcc CFLAGS=-Wall -g eread: node.o $(CC) $(CFLAGS) -o $@ node.o node.c: node.h
And finally the error message is this
C Syntax (Toggle Plain Text)
$ 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?
•
•
Join Date: Oct 2008
Posts: 15
Reputation:
Solved Threads: 1
so new header file is this:
And the error message then becomes:
The warnings are not as troubling to me as the errors, though I am pretty sure that whatever is causing them is related.
c Syntax (Toggle Plain Text)
#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:
C Syntax (Toggle Plain Text)
$ 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:
c Syntax (Toggle Plain Text)
typedef struct node { char value; bool isroot; bool isend; struct node* sibling; struct node* child; }; //<== if semicolon goes here, it's much more reasonable
Last edited by Sci@phy; Oct 26th, 2008 at 7:34 pm.
typedef struct node {
char value;
bool isroot;
bool isend;
struct node* sibling;
struct node* child;
}; "If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
•
•
Join Date: Oct 2008
Posts: 15
Reputation:
Solved Threads: 1
Wow... now I feel... dumb
. Anyway brings me to a final warning
What exactly does this mean?
. Anyway brings me to a final warning C Syntax (Toggle Plain Text)
$ 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:
And the code you wrote has no use from typedef since you haven't specified name that will replace that struct.
It's syntax should be:
c Syntax (Toggle Plain Text)
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?
Where aliasname is any identifier you want to substitute struct node for.
typedef struct node {
char value;
bool isroot;
bool isend;
struct node* sibling;
struct node* child;
} aliasname; "If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
![]() |
Similar Threads
- VB: Connect to Access database via ODBC datasource name (Visual Basic 4 / 5 / 6)
- trie (C++)
- Trie/Tree addWord() method (Computer Science)
- creating a Trie (Java)
- Missing Thumbnails (Web Browsers)
- Computer powers up, does not boot (Troubleshooting Dead Machines)
Other Threads in the C Forum
- Previous Thread: Duplicates project :
- Next Thread: need some help
| Thread Tools | Search this Thread |
Tag cloud for C
#include adobe ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings structures systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






