I have posted about this program before and I thought I had it sorted but it appears I've run into trouble again. I'm makinga program that reads in a text file, reads it and enters all of the words contained within the file into a linked list which will then be seached.
However the program appears to terminate too quickly as it never runs the printf function at the end of the makelist function.
Any help would be grealy appreciated along with any other comments on why the program might not be working as it should.
Code:
typedef struct L {char *word; struct L *next;} List;
int checkchar(char c) {
if (c >= 'a' && c <= 'z') {
return 1;
} else if (c >= 'A' && c <= 'Z') {
return 1;
} else {
return 0;
}
}
List *insertlist(char head[], List *tail, int wordlength) {
List *t = calloc(1, sizeof(List));
strncpy(t->word, head, wordlength);
t->next = tail;
printf("%s\n", head);
return t;
}
List *makelist(char buffer[], int filesize) {
int i=0, j=0, count=0;
char *word;
List *wordlist;
while (i <= filesize) {
if (checkchar(buffer[i]) == 1) {
word[j] = buffer[i];
j++;
} else {
wordlist = insertlist(word, wordlist, i);
j=0;
count++;
}
i++;
}
printf("%d words inserted", count);
return wordlist;
}
the makelist function recieves a string of characters from the main function called "buffer".