I have a text file filled with words (one per line). When I tried this C++ function out, it worked once and then every time after it just returns nothing. What gives?
for (i=0;i<(rand()%10);i++){
if (fin.eof()==true)
fin.seekg(ios::beg);
fin.ignore(256,'/n');
}
fin.getline(word,30);
//TESTING
cout<<"Found random word: "<<word<<endl;
inb4 newprogrammingfagcan'tprogram etc.
Name:
Anonymous2011-02-28 19:59
Rand generates negative numbers as well as positive.
Name:
Anonymous2011-02-28 20:03
If it doesn't find the word, your program won't do anything.
Name:
Anonymous2011-02-28 20:06
2: I thought rand() was unsigned and only generated positive integers?
3: It's not looking for a specific word, just A word. I don't understand why it's not returning anything, because the only stuff in the file is words, /n and EOF.