void populateWorld(string file) {
ifstream fin(file.c_str()); //.c_str() because constructor needs c-string
//make sure the file opened
if (fin.fail()) {
cout << "The file was not found.nPress Enter to quit.";
getchar();
exit(0);
}
//determine the dimensions of the world and create new two-dimensional array
getRow(fin);
getColumn(fin);
allocateMemory();
//fill the world with the contents of the file
for(int i = 0; i < numRows; i++) {
for(int j = 0; j < numColumns; j++) {
world[i][j].status = fin.get();
}
fin.ignore(); //ignore the newline character
}
fin.close();
}
the weird thing is that right after these two function calls, main enters a loop that calls showWorld() at the end of the loop and the output is what's expected every time after the first. any ideas?
okay, never mind. the input file was created in windows. i created a new one with gedit and it worked except the program thought there was one more line in the file than there actually was, so i had a line of garbage.
i have a feeling this has something to do with the difference between windows and unix newline characters, but does anyone have an explanation? i'm curious
also, any reason why the code thinks there one more line than there is in linux, but not in windows? i know how to fix it, but it's weird