Well howdy folks!
This is my first thread/reply at this forum, and just so you know how good/bad I am at this (mostly bad ) I can tell that I know all there is worth to know about HTML, CSS and JavaScript (I know this ain't special). I have started to code in C++ (some jump in huh), and have already read the book "SAMS Teach Yourself C++ in 21 days". Besides this book I've read a bit about this subjet on the net. I have some experience and have, among others, maid this program that seeks for x strings through all files in a submenu or disk. My compiler is Borland 6 (legal it is too) and I know my way around it (not in details though).
As a last comment, before telling what my problem is, "I'm from Denmark, and this I consider as being a perfectly good excuse for all that bad spelling. Though I promise I'll do better next time. I'm just in a hurry at the moment" (Sure!)
This function is a part of a class I've named TFileHandle, which purpose is to take care of files, using streams, without having to do much.
Since a file can have, in theory, endless characters, I've decided to make the code this way.
Plz read my code and comment in betweem, and tell me what I'm doing wrong here.
Code:
AnsiString TFileHandle::Load() const
{
char *Text = new char;
Text[0] = '\0';
char *Temp;
char Char;
unsigned int Lenght;
ifstream File(itsName.c_str());
if (! File.fail())
{
while(! File.eof())
{
Char = File.get();
if (! File.fail())
{
Temp = Text;
Lenght = strlen(Text);
Text = new char[Lenght + 1];
strcpy(Text, Temp);
delete[] Temp; /* <- If I remove this line the program works,
but then I've defiantly crated a memory leak :( */
Text[Lenght] = Char;
Text[Lenght + 1] = '\0';
}
}
}
File.close();
return Text;
}