Here's what I have right now:
Code:
void Player::GetWord()
{
srand( (time(NULL) );
int NumLines(0), RandNum, length;
ifstream File;
char * buffer;
File.open("example.txt")
if(File.is_open())
{
File.seekg(0, ios::end);
length = File.tellg();
File.seekg(0, ios::beg);
buffer = new char [length];
File.read(buffer, length);
for(int x(0); x < length; x++)
{
if(buffer[x] == '\n')
NumLines++;
}
RandNum = rand()%NumLines;
}
}
Is there a way to flag the \n chars? Or should I just record their position in an array? In your example, are you suggesting making an array of strings, each with a different line of the file?