why is duplicate code dangerous?
Code:
do{
x = 0;
do{
a = fgetc (fp);
if (a != ' ' && a != '\n' &&
a != EOF && a !=',' &&
a !=';' && a !='.'&&
a !='!' && a !='?' &&
a !=':' && a !='`'){
word[x] = tolower(a);
x++;
}else{
if (x != 0){
word[x] = '\0';
t = insertList (word, t);
wordcount += 1;
}
}
}while (a != ' ' && a != '\n' &&
a != EOF && a !=',' &&
a !=';' && a !='.'&&
a !='!' && a !='?' &&
a !=':' && a !='`');
} while (a != EOF);
here is my function that reads in characters from a .txt file, forms them into words and puts them in a list excluding characters i specified). i was told that this approach is dangerous for some reason and that i should only test characters once. why is that important and how can i rewrite the above loop? (i need the loop to place words in a list while excluding double spaces as well. i tried doing in with one test but double spaces were included into the list and messed up my word count). thanks