First here is my header file
/* @source Simplespell Program
*
* @author: Chris King(cpking@ncsu.edu)
* @@
*
* node.h
* CSC 230 Fall 2008
*
* The @ signs along with the word denote specific information about
* the program. Using the standards described in:
* http://emboss.sourceforge.net/developers/c-standards_new.html
*/
typedef struct node{ //just creating a node
struct node *array[27]; // a node is merely an array of pointers... TO MORE POINTERS!
}Node, *node_ptr; // wrapping this up
node_ptr createRoot(void); // method to create a root node.
node_ptr addNode(char); //method to add a node to a trie
node_ptr createNode(void); // method to generate a new node
node_ptr buildTrie(node_ptr, char*); // eventually this will compile the trie
int readFile(FILE *);
here is the source code itself
/* @source Simplespell Program
*
* @author: Chris King(cpking@ncsu.edu)
* @@
*
* spellback.c
* CSC 230 Fall 2008
*
* The @ signs along with the word denote specific information about
* the program. Using the standards described in:
* http://emboss.sourceforge.net/developers/c-standards_new.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include "node.h"
#define MAXSIZE 2048 // max size of a char array here (yes i know it could have been 101)
#define MAXLENGTH 100
struct node *rootNode; // our top node in chief.
FILE *inputfile; // any input file here
int main(int argc, char *argv[]){
int ck;
ck = argc;
createRoot();
//printf("%d\n", ck);
FILE *fp;
if(ck == 1){ // checking for no parameters here
printf("Opening default file\n");
readFile(fp = fopen(".WORDS", "r"));
fclose(fp);
printf("Closed default file\n");
}
if(ck == 2 || ck == 4){ // checks for bs parameters here
printf("Invalid Input\n");
return -1;
}
if(ck == 3){ // checks for 1 input file here
printf("Opening default file\n");
fp = fopen(".WORDS", "r");
fclose(fp);
//point fp to next file
printf("Closed default file\n");
fp = fopen(argv[2], "r");
printf("Opening selected file\n");
fclose(fp);
printf("Closed selected file\n");
}
if(ck >= 5){ // checks for more than 5 (this is not finished yet)
printf("Opening default file\n");
fp = fopen(".WORDS", "r");
fclose(fp);
printf("Sorry the rest has not been written yet.\n");
}
return 0;
}
node_ptr createRoot(void){ // this simply uses calloc to allocate the ram for my root trie node
rootNode = calloc(1,sizeof(Node));
return rootNode;
}
node_ptr createNode(void){ // here we find new nodes being created for a trie
struct node *newNode;
newNode = calloc(1,sizeof(Node));
return newNode;
}
int readFile(FILE *inputfile){
char line [MAXLENGTH];
struct node *nodeStart;
nodeStart = rootNode;
printf("I AM BEFORE THE WHILE LOOP.\n");
while(1){
printf("HELP I'M IN A WHILE LOOP.\n");
buildTrie(nodeStart, fgets(line, MAXLENGTH, inputfile));
}
return 0;
}
node_ptr buildTrie(node_ptr nodeIn, char *text){
while(text[0] == '\0'){
break;
}
//rest of code here
printf("we have a line.\n");
return rootNode;
}
the error
$ ./simplespell
Opening default file
I AM BEFORE THE WHILE LOOP.
HELP I'M IN A WHILE LOOP.
we have a line.
HELP I'M IN A WHILE LOOP.
we have a line.
HELP I'M IN A WHILE LOOP.
we have a line.
HELP I'M IN A WHILE LOOP.
we have a line.
HELP I'M IN A WHILE LOOP.
we have a line.
HELP I'M IN A WHILE LOOP.
we have a line.
HELP I'M IN A WHILE LOOP.
CONTINUES FROM HERE FOREVER
I believe the problem is this
while(1){
printf("HELP I'M IN A WHILE LOOP.\n");
buildTrie(nodeStart, fgets(line, MAXLENGTH, inputfile));
}
return 0;
I am trying to get lines until the end of the file, and pass the char array via pointer into the buildTrie function. How can I improve this?