Problem with reading large text files

Started by
0 comments, last by Gammastrahler 21 years, 1 month ago
Hi, i have written a wrapper class for text files. It works fine for many text files i have tested for now. But just for example, i used it to read "DDraw.h" and copy it to a new file. DDraw.h is approximately 137 KB in size, and i have compared the size of bytes in the Explorer with that returned by GetSize(), they were equal. But reading this file and copying the content to a new file, the last 50-60 lines are not in the destination file! The memory buffer is allocated without any error. Look at this source code, please!
    
char *CTextFile::Read(bool close)
{
	if (!Open("r")) return false;

	size_t fSize = GetSize();

	if (fSize == 0) return 0;

	char* buf = new char [fSize+1];

	ZeroMemory(buf, fSize+1);

	if (!buf) return 0;

	fread(buf, fSize, 1, _file);

	if (close) Close();

	return buf;
}
    
Can someone give me a hint what could be wrong here? thanks Gammastrahler [edited by - Gammastrahler on March 19, 2003 3:03:24 AM]
Advertisement
Either the GetSize() function does not return the correct value or the code for "copying the content to a new file" is broken.
Since it is a text file, the problem might be caused by "\r\n" vs. "\n".
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement