The function below has always worked for me until I tried to add in a counter on line 14. As soon as I add in this counter, the while loop is completely neglected. Also mysteriously if I add in line 14 while initialising c to some random value it works again. These seemingly unrelated changes in code make the while loop not execute while the other change makes it work again. Can anyone explain?
Code:struct masternode* foo(ifstream* inputfile) { string word; int i = 0; char c; //defining c to some initialised value makes it work again after adding in line 14. struct masternode* root = NULL; while (c!=EOF){ if((c = (*inputfile).get()) != ' ' && c != ':' && c!= ';' && c!='\n') {word += c; cout<<"aaa";} else { root = insert(root, word); word.clear(); cout << "aaaa"; } //i++; } return root; }