liberty4all
Programmer
Hey everyone,
I am writing a program that reads from a file, separates the words from punctuation marks and aranges arranges the words in alphabetical order in a linked list.
I have a loop, which deals with one line at a time, taking care of every word. It works fine with a 1-line file, but when trying to read the 2nd line, all hell breaks lose. Let me show you my loop...
void main(){
char* token;
char seps[]=" , ; : ! ? - . \n \t ";
char line[128];
WordNode* List;
/*the loop*/
while (fgets(line,128,f)){
token = strtok(line,seps);
while (token!=NULL){
AddWord(&List,token);
token=strtok(NULL,seps);
}
}
}
The first line works perfectly, then when the program hits the while statement for the 2nd time, the list completely changes. The words that were once arranged in the right order now contain weird parts of the remaining text in the file.
*pulls hair*
Someone, please help me....
I am writing a program that reads from a file, separates the words from punctuation marks and aranges arranges the words in alphabetical order in a linked list.
I have a loop, which deals with one line at a time, taking care of every word. It works fine with a 1-line file, but when trying to read the 2nd line, all hell breaks lose. Let me show you my loop...
void main(){
char* token;
char seps[]=" , ; : ! ? - . \n \t ";
char line[128];
WordNode* List;
/*the loop*/
while (fgets(line,128,f)){
token = strtok(line,seps);
while (token!=NULL){
AddWord(&List,token);
token=strtok(NULL,seps);
}
}
}
The first line works perfectly, then when the program hits the while statement for the 2nd time, the list completely changes. The words that were once arranged in the right order now contain weird parts of the remaining text in the file.
*pulls hair*
Someone, please help me....