Start New Discussion within our Software Development Community

With this piece of code when i call read i get the output

Start of loop
Archived filename = ./Data/Test.log
End of loop
Start of loop
Archived File = DATA MANAGER
End of loop

Edit: It is exactly what i want except it adds there odd characters at the end of it. Is there any big reason for this?. I'm very confused about that.
(Code Below)

char * N_Archive::GetFile(char * Filename) {
WriteToLog("Archive: Getting a new file from archive");
char * Buffer;
Archive.seekg(0,ios::beg);
File_D ChunkDat;
std::string Dataz;
WriteToLog("Archive: Prepairing to start chunk reads");
while (!Archive.eof()) {
WriteToLog("Start of loop");
Archive.read(reinterpret_cast<char *>(&ChunkDat),sizeof(File_D));
cout << "Chunk ID: " << ChunkDat.ID << endl << "Chunk Length: " << ChunkDat.Length << endl;
char * Data;
    switch (ChunkDat.ID) {
           case FILE_DATA:
                Data = new char[ChunkDat.Length];
                Archive.read(Data,ChunkDat.Length);
                Dataz = "Archived File = ";
                Dataz += Data;

                WriteToLog(Dataz);
                break;
           case FILE_NAME:
                Data = new char[ChunkDat.Length];
                Archive.read(Data,ChunkDat.Length);
                Dataz = "Archived filename = ";
                Dataz += Data;
                WriteToLog(Dataz);
                break;

    }
WriteToLog("End of loop");
}
return Buffer;
}

PS. I Am very sorry if i have done something wrong this is my first post.

Comments
++ for using code tags correctly on first try :)

I'm not sure what your program is attempting to do, but I do know it contains at least two memory leaks. You use new operator to allocate memory to a Data pointer but never delete[] it before leaving the switch statement.

This article has been dead for over six months. Start a new discussion instead.