Hi,

I'm writing a movie database program. One of the features I want to include is the ability to import a list of movie titles from a text file. The Import function reads in all the titles from a filename of the user's choosing, puts those titles into a list, and then copies that list into another sorted list of movie titles. Here's my code:

Code:
void Import(MovieList& ToList, String FromFile)
{
	ifstream inFile;		//input file stream inFile
	inFile.open(FromFile);//open inFile with user-specified filename

	MovieList FromList;	//list to hold titles from file
	String ImportedTitle;	//a title from the file

	while (inFile)	//while not at the end of the file
	{
		//read in one line of the file as a string
		inFile.getline(ImportedTitle, 40);	

		//add that title from the file into a list
		Add(FromList, ImportedTitle);
	}

	inFile.close();	//close the file

	//the head of the file's title strings
	Movie* FromLocation = FromList.Head;

	//while the title list from the file has not ended
	while (FromLocation != NULL)
	{
		//add title from file list into the database
		Add(ToList, FromLocation->Title);

		//go to next title from file
		FromLocation = FromLocation->Next;
	}
}
When I run this function in my program, I get a runtime error like so:
AFW caused an invalid page fault in
module AFW.EXE at 014f:00413750.
Registers:
EAX=0042fdff CS=014f EIP=00413750 EFLGS=00010286
EBX=00560000 SS=0157 ESP=0066fb68 EBP=0066fb74
ECX=cccccccc DS=0157 ESI=cccccccc FS=3faf
EDX=0066fc48 ES=0157 EDI=0066fc48 GS=0000
Bytes at CS:EIP:
8a 06 46 8a 27 47 38 c4 74 f2 2c 41 3c 1a 1a c9
Stack dump:
00560000 81668408 0066fbe4 0066fbe4 004011e3 0066fc48 cccccccc 0066fcb8 81668408 00560000 cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc


I think this means I have a memory leak that's being caused by one of the two loops. I have no idea why this is happening... the functions and data types used here work flawlessly outside of the Import function, so I don't think that they are to blame.

If anyone can make heads or tails of this, I'd really appreciate it.

Steve