## Recommended Posts

MrSaturnFan    122
I'll bare you with the extreme details of my school assignment. But essentially what I must do is take a text file. (in paragraphs)Take out all the words and put them into a linked list without having duplicates. Now my linked list works and adds the word AND checks for multiples (it also ignores case). My problem is is when i'm reading in it seems. I've debugged it myself (using scanf statements and printing the list after each word is added). It prints properly up until it reaches the end of the line. Then the list gets REALLY screwy, starts adding blank spaces and halves of words. I'll include the important parts of the code:
#define FILENAME "sample.txt"
#define DELIM " ~!@#\$%^&*()_+-={}[]|\\\"\':;<>?,./0123456789\n\r\t"

FILE* input;
char line[1500];
char* str;

int main(int argc, char** argv)
{
char finish;
FILE* input;
char line[1500];
char* str;

initializeLL(&list);

if((input = fopen(FILENAME,"r")) == NULL)
printf("Error opening file");

while((fgets(line,sizeof(line),input))!= NULL)
{
str = strtok(line,DELIM);
if(str!=NULL)

while((str = strtok(NULL,DELIM)) != NULL)
{
if(str!=NULL)
}

}

printLL(list);

scanf("%c",&finish);
fclose(input);

return 0;
}

`
I have reason to believe it's something to do with newline characters. Or maybe i'm not understanding how the fgets function works or the strtok function. And btw, dev-c++'s debugger seems to be broken. So I'm hoping someone can see something I'm missing.

##### Share on other sites
I think that delimiter list is too long. Start simple and then add complexity. For example, start with a single space, " ", then add other punctuation as needed.

For reference: fgets, strtok

##### Share on other sites
Endar    668
For which string function does it say in the linux man pages "Never use this function."? Isn't it strtok?

bakery2k1    712