Hi everyone, another newb with a question. I'm making a function that gets a random line from a file (it's for a hangman type game). I've got it working except that, on occasion, it will return a blank line for a word. I'm not sure where this is coming from exactly:
1 2 3 4 5 6 7 8
for (i=0;i<(rand()%10);i++){
if (fin.eof()==true){
fin.clear();
fin.seekg(0, ios::beg);
}
fin.ignore(256,'\n');
}
fin.getline(word,30);
There are no blank lines in the text file, just strings, \n and EOF. I'm thinking it's trying to getline the EOF? I tried cludging my way around it but it didn't seem to work. What am I doing wrong here?
It's just supposed to jump a random (0-9) lines ahead, and rewind to the beginning if EOF.
It's been a long day, I must not be seeing straight anymore.