C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-08-2004, 08:01 AM   #1
Self-Taught Programmer
 
CodeHacker's Avatar
 
Join Date: Jul 2004
Posts: 12
Question Unknown Memory Leak in Init() Function

I have a memory leak in this init function somewhere. I've looked through it again and again but I can't find it! Someone, please help!
Code:
extern void Init(); 

/* Initialises the program */
extern void Init()
    {
    //Gets the text from Positions.gtx
    DWORD* bytes = new DWORD;    /* Stores bytes read when loading. */
    DWORD* file_size = new DWORD; /* Stores the size of the file containing the game's text. */
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Positions.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Positions.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Position_Text_File = NULL;
    Position_Text_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Position_Text_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes positions text file. */
    separators = new char*[354]; //Creates an array to contain the pointers to the * separators.
    
    //Fills the array in and replaces the *s with nulls.
    separators[0] = strstr(Position_Text_File,"*"); *separators[0] = '\0';
    separators[1] = strstr(separators[0]+1,"*"); *separators[1] = '\0';
    separators[2] = strstr(separators[1]+1,"*"); *separators[2] = '\0';
    separators[3] = strstr(separators[2]+1,"*"); *separators[3] = '\0';
    separators[4] = strstr(separators[3]+1,"*"); *separators[4] = '\0';
    separators[5] = strstr(separators[4]+1,"*"); *separators[5] = '\0';
    separators[6] = strstr(separators[5]+1,"*"); *separators[6] = '\0';
    separators[7] = strstr(separators[6]+1,"*"); *separators[7] = '\0';
    separators[8] = strstr(separators[7]+1,"*"); *separators[8] = '\0';
    separators[9] = strstr(separators[8]+1,"*"); *separators[9] = '\0';
    separators[10] = strstr(separators[9]+1,"*"); *separators[10] = '\0';
    separators[11] = strstr(separators[10]+1,"*"); *separators[11] = '\0';
    separators[12] = strstr(separators[11]+1,"*"); *separators[12] = '\0';
    separators[13] = strstr(separators[12]+1,"*"); *separators[13] = '\0';
    separators[14] = strstr(separators[13]+1,"*"); *separators[14] = '\0';
    separators[15] = strstr(separators[14]+1,"*"); *separators[15] = '\0';
    separators[16] = strstr(separators[15]+1,"*"); *separators[16] = '\0';
    separators[17] = strstr(separators[16]+1,"*"); *separators[17] = '\0';
    separators[18] = strstr(separators[17]+1,"*"); *separators[18] = '\0';
    separators[19] = strstr(separators[18]+1,"*"); *separators[19] = '\0';
    separators[20] = strstr(separators[19]+1,"*"); *separators[20] = '\0';
    separators[21] = strstr(separators[20]+1,"*"); *separators[21] = '\0';
    separators[22] = strstr(separators[21]+1,"*"); *separators[22] = '\0';
    separators[23] = strstr(separators[22]+1,"*"); *separators[23] = '\0';
    separators[24] = strstr(separators[23]+1,"*"); *separators[24] = '\0';
    separators[25] = strstr(separators[24]+1,"*"); *separators[25] = '\0';
    separators[26] = strstr(separators[25]+1,"*"); *separators[26] = '\0';
    separators[27] = strstr(separators[26]+1,"*"); *separators[27] = '\0';
    separators[28] = strstr(separators[27]+1,"*"); *separators[28] = '\0';
    separators[29] = strstr(separators[28]+1,"*"); *separators[29] = '\0';
    separators[30] = strstr(separators[29]+1,"*"); *separators[30] = '\0';
    separators[31] = strstr(separators[30]+1,"*"); *separators[31] = '\0';
    separators[32] = strstr(separators[31]+1,"*"); *separators[32] = '\0';
    separators[33] = strstr(separators[32]+1,"*"); *separators[33] = '\0';
    separators[34] = strstr(separators[33]+1,"*"); *separators[34] = '\0';
    separators[35] = strstr(separators[34]+1,"*"); *separators[35] = '\0';
    separators[36] = strstr(separators[35]+1,"*"); *separators[36] = '\0';
    separators[37] = strstr(separators[36]+1,"*"); *separators[37] = '\0';
    separators[38] = strstr(separators[37]+1,"*"); *separators[38] = '\0';
    separators[39] = strstr(separators[38]+1,"*"); *separators[39] = '\0';
    separators[40] = strstr(separators[39]+1,"*"); *separators[40] = '\0';
    separators[41] = strstr(separators[40]+1,"*"); *separators[41] = '\0';
    separators[42] = strstr(separators[41]+1,"*"); *separators[42] = '\0';
    separators[43] = strstr(separators[42]+1,"*"); *separators[43] = '\0';
    separators[44] = strstr(separators[43]+1,"*"); *separators[44] = '\0';
    separators[45] = strstr(separators[44]+1,"*"); *separators[45] = '\0';
    
    //Gets the text from Position Variables.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Position Variables.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Positions Variables.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Position_Variables_Text_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Position_Variables_Text_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes position variables text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[46] = strstr(Position_Variables_Text_File,"*"); *separators[46] = '\0';
    separators[47] = strstr(separators[46]+1,"*"); *separators[47] = '\0';
    separators[48] = strstr(separators[47]+1,"*"); *separators[48] = '\0';
    separators[49] = strstr(separators[48]+1,"*"); *separators[49] = '\0';
    separators[50] = strstr(separators[49]+1,"*"); *separators[50] = '\0';
    separators[51] = strstr(separators[50]+1,"*"); *separators[51] = '\0';
    separators[52] = strstr(separators[51]+1,"*"); *separators[52] = '\0';
    separators[53] = strstr(separators[52]+1,"*"); *separators[53] = '\0';
    
    //Gets the text from Item Names.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Item Names.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Item Names.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Item_Names_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Item_Names_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[54] = strstr(Item_Names_File,"*"); *separators[54] = '\0';
    separators[55] = strstr(separators[54]+1,"*"); *separators[55] = '\0';
    separators[56] = strstr(separators[55]+1,"*"); *separators[56] = '\0';
    separators[57] = strstr(separators[56]+1,"*"); *separators[57] = '\0';
    separators[58] = strstr(separators[57]+1,"*"); *separators[58] = '\0';
    separators[59] = strstr(separators[58]+1,"*"); *separators[59] = '\0';
    separators[60] = strstr(separators[59]+1,"*"); *separators[60] = '\0';
    separators[61] = strstr(separators[60]+1,"*"); *separators[61] = '\0';
    separators[62] = strstr(separators[61]+1,"*"); *separators[62] = '\0';
    separators[63] = strstr(separators[62]+1,"*"); *separators[63] = '\0';
    separators[64] = strstr(separators[63]+1,"*"); *separators[64] = '\0';
    separators[65] = strstr(separators[64]+1,"*"); *separators[65] = '\0';
    separators[66] = strstr(separators[65]+1,"*"); *separators[66] = '\0';
    separators[67] = strstr(separators[66]+1,"*"); *separators[67] = '\0';
    separators[68] = strstr(separators[67]+1,"*"); *separators[68] = '\0';
    separators[69] = strstr(separators[68]+1,"*"); *separators[69] = '\0';
    separators[70] = strstr(separators[69]+1,"*"); *separators[70] = '\0';
    separators[71] = strstr(separators[70]+1,"*"); *separators[71] = '\0';
    strcpy(Empty.Name,separators[55]+1);
    strcpy(W_Sword.Name,separators[57]+1);
    strcpy(A_Clothes.Name,separators[59]+1);
    strcpy(Potion.Name,separators[61]+1);
    strcpy(Tent.Name,separators[63]+1);
    strcpy(Grain.Name,separators[65]+1);
    strcpy(W_LSword.Name,separators[67]+1);
    strcpy(A_ChainMail.Name,separators[69]+1);
    
    //Gets the text from Textboxes.gtx
    bytes = new DWORD;    /* Stores bytes read when loading. */
    file_size = new DWORD; /* Stores the size of the file containing the game's text. */
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Textboxes.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Textboxes.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Textboxes_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Textboxes_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[72] = strstr(Textboxes_File,"*"); *separators[72] = '\0';
    separators[73] = strstr(separators[72]+1,"*"); *separators[73] = '\0';
    separators[74] = strstr(separators[73]+1,"*"); *separators[74] = '\0';
    separators[75] = strstr(separators[74]+1,"*"); *separators[75] = '\0';
    separators[76] = strstr(separators[75]+1,"*"); *separators[76] = '\0';
    separators[77] = strstr(separators[76]+1,"*"); *separators[77] = '\0';
    separators[78] = strstr(separators[77]+1,"*"); *separators[78] = '\0';
    separators[79] = strstr(separators[78]+1,"*"); *separators[79] = '\0';
    separators[80] = strstr(separators[79]+1,"*"); *separators[80] = '\0';
    separators[81] = strstr(separators[80]+1,"*"); *separators[81] = '\0';
    separators[82] = strstr(separators[81]+1,"*"); *separators[82] = '\0';
    separators[83] = strstr(separators[82]+1,"*"); *separators[83] = '\0';
    separators[84] = strstr(separators[83]+1,"*"); *separators[84] = '\0';
    separators[85] = strstr(separators[84]+1,"*"); *separators[85] = '\0';
    separators[86] = strstr(separators[85]+1,"*"); *separators[86] = '\0';
    separators[87] = strstr(separators[86]+1,"*"); *separators[87] = '\0';
    separators[88] = strstr(separators[87]+1,"*"); *separators[88] = '\0';
    separators[89] = strstr(separators[88]+1,"*"); *separators[89] = '\0';
    
    //Gets the text from Help.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Help.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Help.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Help_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Help_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[90] = strstr(Help_File,"*"); *separators[90] = '\0';
    separators[91] = strstr(separators[90]+1,"*"); *separators[91] = '\0';
    separators[92] = strstr(separators[91]+1,"*"); *separators[92] = '\0';
    separators[93] = strstr(separators[92]+1,"*"); *separators[93] = '\0';
    separators[94] = strstr(separators[93]+1,"*"); *separators[94] = '\0';
    separators[95] = strstr(separators[94]+1,"*"); *separators[95] = '\0';
    separators[96] = strstr(separators[95]+1,"*"); *separators[96] = '\0';
    separators[97] = strstr(separators[96]+1,"*"); *separators[97] = '\0';
    separators[98] = strstr(separators[97]+1,"*"); *separators[98] = '\0';
    separators[99] = strstr(separators[98]+1,"*"); *separators[99] = '\0';
    separators[100] = strstr(separators[99]+1,"*"); *separators[100] = '\0';
    separators[101] = strstr(separators[100]+1,"*"); *separators[101] = '\0';
    separators[102] = strstr(separators[101]+1,"*"); *separators[102] = '\0';
    separators[103] = strstr(separators[102]+1,"*"); *separators[103] = '\0';
    
    //Gets the text from Messages.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Messages.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Messages.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Messages_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Messages_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[104] = strstr(Messages_File,"*"); *separators[104] = '\0';
    separators[105] = strstr(separators[104]+1,"*"); *separators[105] = '\0';
    separators[106] = strstr(separators[105]+1,"*"); *separators[106] = '\0';
    separators[107] = strstr(separators[106]+1,"*"); *separators[107] = '\0';
    separators[108] = strstr(separators[107]+1,"*"); *separators[108] = '\0';
    separators[109] = strstr(separators[108]+1,"*"); *separators[109] = '\0';
    separators[110] = strstr(separators[109]+1,"*"); *separators[110] = '\0';
    separators[111] = strstr(separators[110]+1,"*"); *separators[111] = '\0';
    separators[112] = strstr(separators[111]+1,"*"); *separators[112] = '\0';
    separators[113] = strstr(separators[112]+1,"*"); *separators[113] = '\0';
    separators[114] = strstr(separators[113]+1,"*"); *separators[114] = '\0';
    separators[115] = strstr(separators[114]+1,"*"); *separators[115] = '\0';
    separators[116] = strstr(separators[115]+1,"*"); *separators[116] = '\0';
    separators[117] = strstr(separators[116]+1,"*"); *separators[117] = '\0';
    separators[118] = strstr(separators[117]+1,"*"); *separators[118] = '\0';
    separators[119] = strstr(separators[118]+1,"*"); *separators[119] = '\0';
    
    //Gets the text from Item Messages.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Item Messages.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Item Messages.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Item_Messages_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Item_Messages_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[120] = strstr(Item_Messages_File,"*"); *separators[120] = '\0';
    separators[121] = strstr(separators[120]+1,"*"); *separators[121] = '\0';
    separators[122] = strstr(separators[121]+1,"*"); *separators[122] = '\0';
    separators[123] = strstr(separators[122]+1,"*"); *separators[123] = '\0';
    separators[124] = strstr(separators[123]+1,"*"); *separators[124] = '\0';
    separators[125] = strstr(separators[124]+1,"*"); *separators[125] = '\0';
    separators[126] = strstr(separators[125]+1,"*"); *separators[126] = '\0';
    separators[127] = strstr(separators[126]+1,"*"); *separators[127] = '\0';
    separators[128] = strstr(separators[127]+1,"*"); *separators[128] = '\0';
    separators[129] = strstr(separators[128]+1,"*"); *separators[129] = '\0';
    separators[130] = strstr(separators[129]+1,"*"); *separators[130] = '\0';
    separators[131] = strstr(separators[130]+1,"*"); *separators[131] = '\0';
    separators[132] = strstr(separators[131]+1,"*"); *separators[132] = '\0';
    separators[133] = strstr(separators[132]+1,"*"); *separators[133] = '\0';
    separators[134] = strstr(separators[133]+1,"*"); *separators[134] = '\0';
    separators[135] = strstr(separators[134]+1,"*"); *separators[135] = '\0';
    separators[136] = strstr(separators[135]+1,"*"); *separators[136] = '\0';
    separators[137] = strstr(separators[136]+1,"*"); *separators[137] = '\0';
    separators[138] = strstr(separators[137]+1,"*"); *separators[138] = '\0';
    
    //Gets the text from Input Messages.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Input Messages.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Input Messages.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Input_Messages_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Input_Messages_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[139] = strstr(Input_Messages_File,"*"); *separators[139] = '\0';
    separators[140] = strstr(separators[139]+1,"*"); *separators[140] = '\0';
    separators[141] = strstr(separators[140]+1,"*"); *separators[141] = '\0';
    separators[142] = strstr(separators[141]+1,"*"); *separators[142] = '\0';
    separators[143] = strstr(separators[142]+1,"*"); *separators[143] = '\0';
    separators[144] = strstr(separators[143]+1,"*"); *separators[144] = '\0';
    separators[145] = strstr(separators[144]+1,"*"); *separators[145] = '\0';
    separators[146] = strstr(separators[145]+1,"*"); *separators[146] = '\0';
    separators[147] = strstr(separators[146]+1,"*"); *separators[147] = '\0';
    separators[148] = strstr(separators[147]+1,"*"); *separators[148] = '\0';
    separators[149] = strstr(separators[148]+1,"*"); *separators[149] = '\0';
    separators[150] = strstr(separators[149]+1,"*"); *separators[150] = '\0';
    separators[151] = strstr(separators[150]+1,"*"); *separators[151] = '\0';
    separators[152] = strstr(separators[151]+1,"*"); *separators[152] = '\0';
    separators[153] = strstr(separators[152]+1,"*"); *separators[153] = '\0';
    separators[154] = strstr(separators[153]+1,"*"); *separators[154] = '\0';
    separators[155] = strstr(separators[154]+1,"*"); *separators[155] = '\0';
    separators[156] = strstr(separators[155]+1,"*"); *separators[156] = '\0';
    separators[157] = strstr(separators[156]+1,"*"); *separators[157] = '\0';
    separators[158] = strstr(separators[157]+1,"*"); *separators[158] = '\0';
    separators[159] = strstr(separators[158]+1,"*"); *separators[159] = '\0';
    separators[160] = strstr(separators[159]+1,"*"); *separators[160] = '\0';
    separators[161] = strstr(separators[160]+1,"*"); *separators[161] = '\0';
    separators[162] = strstr(separators[161]+1,"*"); *separators[162] = '\0';
    separators[163] = strstr(separators[162]+1,"*"); *separators[163] = '\0';
    separators[164] = strstr(separators[163]+1,"*"); *separators[164] = '\0';
    separators[165] = strstr(separators[164]+1,"*"); *separators[165] = '\0';
    separators[166] = strstr(separators[165]+1,"*"); *separators[166] = '\0';
    separators[167] = strstr(separators[166]+1,"*"); *separators[167] = '\0';
    separators[168] = strstr(separators[167]+1,"*"); *separators[168] = '\0';
    separators[169] = strstr(separators[168]+1,"*"); *separators[169] = '\0';
    separators[170] = strstr(separators[169]+1,"*"); *separators[170] = '\0';
    separators[171] = strstr(separators[170]+1,"*"); *separators[171] = '\0';
    separators[172] = strstr(separators[171]+1,"*"); *separators[172] = '\0';
    separators[173] = strstr(separators[172]+1,"*"); *separators[173] = '\0';
    separators[174] = strstr(separators[173]+1,"*"); *separators[174] = '\0';
    separators[175] = strstr(separators[174]+1,"*"); *separators[175] = '\0';
    separators[176] = strstr(separators[175]+1,"*"); *separators[176] = '\0';
    separators[177] = strstr(separators[176]+1,"*"); *separators[177] = '\0';
    separators[178] = strstr(separators[177]+1,"*"); *separators[178] = '\0';
    separators[179] = strstr(separators[178]+1,"*"); *separators[179] = '\0';
    separators[180] = strstr(separators[179]+1,"*"); *separators[180] = '\0';
    separators[181] = strstr(separators[180]+1,"*"); *separators[181] = '\0';
    separators[182] = strstr(separators[181]+1,"*"); *separators[182] = '\0';
    separators[183] = strstr(separators[182]+1,"*"); *separators[183] = '\0';
    separators[184] = strstr(separators[183]+1,"*"); *separators[184] = '\0';
    separators[185] = strstr(separators[184]+1,"*"); *separators[185] = '\0';
    separators[186] = strstr(separators[185]+1,"*"); *separators[186] = '\0';
    separators[187] = strstr(separators[186]+1,"*"); *separators[187] = '\0';
    separators[188] = strstr(separators[187]+1,"*"); *separators[188] = '\0';
    separators[189] = strstr(separators[188]+1,"*"); *separators[189] = '\0';
    separators[190] = strstr(separators[189]+1,"*"); *separators[190] = '\0';
    separators[191] = strstr(separators[190]+1,"*"); *separators[191] = '\0';
    separators[192] = strstr(separators[191]+1,"*"); *separators[192] = '\0';
    separators[193] = strstr(separators[192]+1,"*"); *separators[193] = '\0';
    separators[194] = strstr(separators[193]+1,"*"); *separators[194] = '\0';
    separators[195] = strstr(separators[194]+1,"*"); *separators[195] = '\0';
    separators[196] = strstr(separators[195]+1,"*"); *separators[196] = '\0';
    separators[197] = strstr(separators[196]+1,"*"); *separators[197] = '\0';
    separators[198] = strstr(separators[197]+1,"*"); *separators[198] = '\0';
    separators[199] = strstr(separators[198]+1,"*"); *separators[199] = '\0';
    separators[200] = strstr(separators[199]+1,"*"); *separators[200] = '\0';
    separators[201] = strstr(separators[200]+1,"*"); *separators[201] = '\0';
    separators[202] = strstr(separators[201]+1,"*"); *separators[202] = '\0';
    separators[203] = strstr(separators[202]+1,"*"); *separators[203] = '\0';
    separators[204] = strstr(separators[203]+1,"*"); *separators[204] = '\0';
    separators[205] = strstr(separators[204]+1,"*"); *separators[205] = '\0';
    separators[206] = strstr(separators[205]+1,"*"); *separators[206] = '\0';
    separators[207] = strstr(separators[206]+1,"*"); *separators[207] = '\0';
    separators[208] = strstr(separators[207]+1,"*"); *separators[208] = '\0';
    separators[209] = strstr(separators[208]+1,"*"); *separators[209] = '\0';
    separators[210] = strstr(separators[209]+1,"*"); *separators[210] = '\0';
    separators[211] = strstr(separators[210]+1,"*"); *separators[211] = '\0';
    separators[212] = strstr(separators[211]+1,"*"); *separators[212] = '\0';
    
    //Gets the text from Item Selling - Position 3.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Item Selling - Position 3.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Item Selling - Position 3.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Item_Selling_P3_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Item_Selling_P3_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[213] = strstr(Item_Selling_P3_File,"*"); *separators[213] = '\0';
    separators[214] = strstr(separators[213]+1,"*"); *separators[214] = '\0';
    separators[215] = strstr(separators[214]+1,"*"); *separators[215] = '\0';
    separators[216] = strstr(separators[215]+1,"*"); *separators[216] = '\0';
    separators[217] = strstr(separators[216]+1,"*"); *separators[217] = '\0';
    separators[218] = strstr(separators[217]+1,"*"); *separators[218] = '\0';
    separators[219] = strstr(separators[218]+1,"*"); *separators[219] = '\0';
    separators[220] = strstr(separators[219]+1,"*"); *separators[220] = '\0';
    separators[221] = strstr(separators[220]+1,"*"); *separators[221] = '\0';
    separators[222] = strstr(separators[221]+1,"*"); *separators[222] = '\0';
    separators[223] = strstr(separators[222]+1,"*"); *separators[223] = '\0';
    separators[224] = strstr(separators[223]+1,"*"); *separators[224] = '\0';
    separators[225] = strstr(separators[224]+1,"*"); *separators[225] = '\0';
    separators[226] = strstr(separators[225]+1,"*"); *separators[226] = '\0';
    separators[227] = strstr(separators[226]+1,"*"); *separators[227] = '\0';
    separators[228] = strstr(separators[227]+1,"*"); *separators[228] = '\0';
    separators[229] = strstr(separators[228]+1,"*"); *separators[229] = '\0';
    separators[230] = strstr(separators[229]+1,"*"); *separators[230] = '\0';
    separators[231] = strstr(separators[230]+1,"*"); *separators[231] = '\0';
    separators[232] = strstr(separators[231]+1,"*"); *separators[232] = '\0';
    separators[233] = strstr(separators[232]+1,"*"); *separators[233] = '\0';
    separators[234] = strstr(separators[233]+1,"*"); *separators[234] = '\0';
    separators[235] = strstr(separators[234]+1,"*"); *separators[235] = '\0';
    separators[236] = strstr(separators[235]+1,"*"); *separators[236] = '\0';
    separators[237] = strstr(separators[236]+1,"*"); *separators[237] = '\0';
    separators[238] = strstr(separators[237]+1,"*"); *separators[238] = '\0';
    separators[239] = strstr(separators[238]+1,"*"); *separators[239] = '\0';
    separators[240] = strstr(separators[239]+1,"*"); *separators[240] = '\0';
    separators[241] = strstr(separators[240]+1,"*"); *separators[241] = '\0';
    separators[242] = strstr(separators[241]+1,"*"); *separators[242] = '\0';
    separators[243] = strstr(separators[242]+1,"*"); *separators[243] = '\0';
    separators[244] = strstr(separators[243]+1,"*"); *separators[244] = '\0';
    separators[245] = strstr(separators[244]+1,"*"); *separators[245] = '\0';
    
    //Gets the text from Item Selling - Position 4.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Item Selling - Position 4.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Item Selling - Position 4.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Item_Selling_P4_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Item_Selling_P4_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[246] = strstr(Item_Selling_P4_File,"*"); *separators[246] = '\0';
    separators[247] = strstr(separators[246]+1,"*"); *separators[247] = '\0';
    separators[248] = strstr(separators[247]+1,"*"); *separators[248] = '\0';
    separators[249] = strstr(separators[248]+1,"*"); *separators[249] = '\0';
    separators[250] = strstr(separators[249]+1,"*"); *separators[250] = '\0';
    separators[251] = strstr(separators[250]+1,"*"); *separators[251] = '\0';
    separators[252] = strstr(separators[251]+1,"*"); *separators[252] = '\0';
    separators[253] = strstr(separators[252]+1,"*"); *separators[253] = '\0';
    
    //Gets the text from Position Options.gtx
    ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Position Options.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NULL,"Could Not Open File - Position Options.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Position_Options_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Position_Options_File,*file_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes item names text file. */
    /* Deletes the above DWORDs */
    delete bytes; 
    delete file_size;
    
    //Fills the separator array in and replaces the *s with nulls.
    separators[254] = strstr(Position_Options_File,"*"); *separators[254] = '\0';
    separators[255] = strstr(separators[254]+1,"*"); *separators[255] = '\0';
    separators[256] = strstr(separators[255]+1,"*"); *separators[256] = '\0';
    separators[257] = strstr(separators[256]+1,"*"); *separators[257] = '\0';
    separators[258] = strstr(separators[257]+1,"*"); *separators[258] = '\0';
    separators[259] = strstr(separators[258]+1,"*"); *separators[259] = '\0';
    separators[260] = strstr(separators[259]+1,"*"); *separators[260] = '\0';
    separators[261] = strstr(separators[260]+1,"*"); *separators[261] = '\0';
    separators[262] = strstr(separators[261]+1,"*"); *separators[262] = '\0';
    separators[263] = strstr(separators[262]+1,"*"); *separators[263] = '\0';
    separators[264] = strstr(separators[263]+1,"*"); *separators[264] = '\0';
    separators[265] = strstr(separators[264]+1,"*"); *separators[265] = '\0';
    separators[266] = strstr(separators[265]+1,"*"); *separators[266] = '\0';
    separators[267] = strstr(separators[266]+1,"*"); *separators[267] = '\0';
    separators[268] = strstr(separators[267]+1,"*"); *separators[268] = '\0';
    separators[269] = strstr(separators[268]+1,"*"); *separators[269] = '\0';
    separators[270] = strstr(separators[269]+1,"*"); *separators[270] = '\0';
    separators[271] = strstr(separators[270]+1,"*"); *separators[271] = '\0';
    separators[272] = strstr(separators[271]+1,"*"); *separators[272] = '\0';
    separators[273] = strstr(separators[272]+1,"*"); *separators[273] = '\0';
    separators[274] = strstr(separators[273]+1,"*"); *separators[274] = '\0';
    separators[275] = strstr(separators[274]+1,"*"); *separators[275] = '\0';
    separators[276] = strstr(separators[275]+1,"*"); *separators[276] = '\0';
    separators[277] = strstr(separators[276]+1,"*"); *separators[277] = '\0';
    separators[278] = strstr(separators[277]+1,"*"); *separators[278] = '\0';
    separators[279] = strstr(separators[278]+1,"*"); *separators[279] = '\0';
    separators[280] = strstr(separators[279]+1,"*"); *separators[280] = '\0';
    separators[281] = strstr(separators[280]+1,"*"); *separators[281] = '\0';
    separators[282] = strstr(separators[281]+1,"*"); *separators[282] = '\0';
    separators[283] = strstr(separators[282]+1,"*"); *separators[283] = '\0';
    separators[284] = strstr(separators[283]+1,"*"); *separators[284] = '\0';
    separators[285] = strstr(separators[284]+1,"*"); *separators[285] = '\0';
    separators[286] = strstr(separators[285]+1,"*"); *separators[286] = '\0';
    separators[287] = strstr(separators[286]+1,"*"); *separators[287] = '\0';
    separators[288] = strstr(separators[287]+1,"*"); *separators[288] = '\0';
    separators[289] = strstr(separators[288]+1,"*"); *separators[289] = '\0';
    separators[290] = strstr(separators[289]+1,"*"); *separators[290] = '\0';
    separators[291] = strstr(separators[290]+1,"*"); *separators[291] = '\0';
    separators[292] = strstr(separators[291]+1,"*"); *separators[292] = '\0';
    separators[293] = strstr(separators[292]+1,"*"); *separators[293] = '\0';
    separators[294] = strstr(separators[293]+1,"*"); *separators[294] = '\0';
    separators[295] = strstr(separators[294]+1,"*"); *separators[295] = '\0';
    separators[296] = strstr(separators[295]+1,"*"); *separators[296] = '\0';
    separators[297] = strstr(separators[296]+1,"*"); *separators[297] = '\0';
    separators[298] = strstr(separators[297]+1,"*"); *separators[298] = '\0';
    separators[299] = strstr(separators[298]+1,"*"); *separators[299] = '\0';
    separators[300] = strstr(separators[299]+1,"*"); *separators[300] = '\0';
    separators[301] = strstr(separators[300]+1,"*"); *separators[301] = '\0';
    separators[302] = strstr(separators[301]+1,"*"); *separators[302] = '\0';
    separators[303] = strstr(separators[302]+1,"*"); *separators[303] = '\0';
    separators[304] = strstr(separators[303]+1,"*"); *separators[304] = '\0';
    separators[305] = strstr(separators[304]+1,"*"); *separators[305] = '\0';
    separators[306] = strstr(separators[305]+1,"*"); *separators[306] = '\0';
    separators[307] = strstr(separators[306]+1,"*"); *separators[307] = '\0';
    separators[308] = strstr(separators[307]+1,"*"); *separators[308] = '\0';
    separators[309] = strstr(separators[308]+1,"*"); *separators[309] = '\0';
    separators[310] = strstr(separators[309]+1,"*"); *separators[310] = '\0';
    separators[311] = strstr(separators[310]+1,"*"); *separators[311] = '\0';
    separators[312] = strstr(separators[311]+1,"*"); *separators[312] = '\0';
    separators[313] = strstr(separators[312]+1,"*"); *separators[313] = '\0';
    separators[314] = strstr(separators[313]+1,"*"); *separators[314] = '\0';
    separators[315] = strstr(separators[314]+1,"*"); *separators[315] = '\0';
    separators[316] = strstr(separators[315]+1,"*"); *separators[316] = '\0';
    separators[317] = strstr(separators[316]+1,"*"); *separators[317] = '\0';
    separators[318] = strstr(separators[317]+1,"*"); *separators[318] = '\0';
    separators[319] = strstr(separators[318]+1,"*"); *separators[319] = '\0';
    separators[320] = strstr(separators[319]+1,"*"); *separators[320] = '\0';
    separators[321] = strstr(separators[320]+1,"*"); *separators[321] = '\0';
    separators[322] = strstr(separators[321]+1,"*"); *separators[322] = '\0';
    separators[323] = strstr(separators[322]+1,"*"); *separators[323] = '\0';
    separators[324] = strstr(separators[323]+1,"*"); *separators[324] = '\0';
    separators[325] = strstr(separators[324]+1,"*"); *separators[325] = '\0';
    separators[326] = strstr(separators[325]+1,"*"); *separators[326] = '\0';
    separators[327] = strstr(separators[326]+1,"*"); *separators[327] = '\0';
    separators[328] = strstr(separators[327]+1,"*"); *separators[328] = '\0';
    separators[329] = strstr(separators[328]+1,"*"); *separators[329] = '\0';
    separators[330] = strstr(separators[329]+1,"*"); *separators[330] = '\0';
    separators[331] = strstr(separators[330]+1,"*"); *separators[331] = '\0';
    separators[332] = strstr(separators[331]+1,"*"); *separators[332] = '\0';
    separators[333] = strstr(separators[332]+1,"*"); *separators[333] = '\0';
    separators[334] = strstr(separators[333]+1,"*"); *separators[334] = '\0';
    separators[335] = strstr(separators[334]+1,"*"); *separators[335] = '\0';
    separators[336] = strstr(separators[335]+1,"*"); *separators[336] = '\0';
    separators[337] = strstr(separators[336]+1,"*"); *separators[337] = '\0';
    separators[338] = strstr(separators[337]+1,"*"); *separators[338] = '\0';
    separators[339] = strstr(separators[338]+1,"*"); *separators[339] = '\0';
    separators[340] = strstr(separators[339]+1,"*"); *separators[340] = '\0';
    separators[341] = strstr(separators[340]+1,"*"); *separators[341] = '\0';
    separators[342] = strstr(separators[341]+1,"*"); *separators[342] = '\0';
    separators[343] = strstr(separators[342]+1,"*"); *separators[343] = '\0';
    separators[344] = strstr(separators[343]+1,"*"); *separators[344] = '\0';
    separators[345] = strstr(separators[344]+1,"*"); *separators[345] = '\0';
    separators[346] = strstr(separators[345]+1,"*"); *separators[346] = '\0';
    separators[347] = strstr(separators[346]+1,"*"); *separators[347] = '\0';
    separators[348] = strstr(separators[347]+1,"*"); *separators[348] = '\0';
    separators[349] = strstr(separators[348]+1,"*"); *separators[349] = '\0';
    separators[350] = strstr(separators[349]+1,"*"); *separators[350] = '\0';
    separators[351] = strstr(separators[350]+1,"*"); *separators[351] = '\0';
    separators[352] = strstr(separators[351]+1,"*"); *separators[352] = '\0';
    separators[353] = strstr(separators[352]+1,"*"); *separators[353] = '\0';

    //Resets the Inventory.   
    *Inventory1 = Empty;
    *Inventory2 = Empty;
    *Inventory3 = Empty;
    *Inventory4 = Empty;
    *Inventory5 = Empty;
    *Inventory6 = Empty;
    *Inventory7 = Empty;
    *Inventory8 = Empty;
    *Inventory9 = Empty;
    *Inventory10 = Empty;
    
    //Sets up the update variables.
    Changed=1;
    Level_Changed = 0;
    Position_Changed = 1;
    
    //Sets up inital level and stats.
    Exp_To_Next_Level = 0;
    Level = 0;
    Max_HP = 0;
    Strength = 0;
    Defence = 0;
    
    //Sets up inital health, money. and time.
    HP = Max_HP;
    Gold_Coins = 0;
    Time[0] = 0;
    Time[1] = 0;
    
    Weapon = Empty;
    Weapon_Attack = 0;
    Armour = Empty;
    Armour_Defence = 0;
    
    //Sets up game variables.
    Variables[0] = 1; //Whether you have slept.
    Variables[1] = 0; //Whether the game has checked that you have slept.
    Variables[2] = 0; //Whether your bed is messy.
    Variables[3] = 0; //Whether you have got your item pack from under your bed.
    Variables[4] = 0; //Whether the gate to the town is open.
    Variables[5] = 0; //Whether you have been to Larn Village street.
    Variables[6] = 0; //Whether you have been to Larn Village farm.
    Variables[7] = 0; //Whether you have searched Larn Village farm.
    Old_Position = -1;
    Position = -1;
    Position_Type = -1;
    Position_Outside = 0; 
    Sub_Position = 0;
    
    //Initialises Shop Variables
    Buying = 0;
    Item_To_Buy = 0;
    Sell_Price = 0;
    
    //Sets up your inital item quantities.
    int x = 0;
    while(x < 10){InventoryQ[x]=0; x++;}
    
    Battle = 0;
    
    //Sets the Message Box and Title Box up with inital text.
    TB_Title->TB_Text_Length = wsprintf(TB_Title->TB_Text,separators[73]+1);
    strcpy(Message,separators[105]+1);}
This may be called more than once to reset the program. If it is called again, the following code runs before it -
Code:
//Deletes allocated arrays.
                        delete[] Position_Text_File;
                        delete[] Position_Variables_Text_File;
                        delete[] Item_Names_File;
                        delete[] Textboxes_File;
                        delete[] Help_File;
                        delete[] Item_Messages_File;
                        delete[] Input_Messages_File;
                        delete[] Item_Selling_P3_File;
                        delete[] Item_Selling_P4_File;
                        delete[] Position_Options_File;
                        delete[] separators;
                        
                        Init();
CodeHacker is offline   Reply With Quote
Old 07-08-2004, 01:20 PM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
Try writing some of that using a for loop - that is just simply horrible to read

> if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NUL L,
You don't get any bonus points for compressing all this onto one line without any white space

> DWORD* bytes = new DWORD;
You do new twice and delete once
Besides, what's the point of allocating just once DWORD?

DWORD bytes;
...
ReadFile(Text_File,Input_Messages_File,*file_size, &bytes,NULL);

Does the same thing, and no messy allocation to tidy up
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 07-08-2004, 02:45 PM   #3
Yes, my avatar is stolen
 
anonytmouse's Avatar
 
Join Date: Dec 2002
Posts: 2,544
Expanding on what Salem said...

Compare:
Code:
   separators[255] = strstr(separators[254]+1,"*"); *separators[255] = '\0';
    separators[256] = strstr(separators[255]+1,"*"); *separators[256] = '\0';
    separators[257] = strstr(separators[256]+1,"*"); *separators[257] = '\0';
    separators[258] = strstr(separators[257]+1,"*"); *separators[258] = '\0';
    separators[259] = strstr(separators[258]+1,"*"); *separators[259] = '\0';
    separators[260] = strstr(separators[259]+1,"*"); *separators[260] = '\0';
...
    separators[350] = strstr(separators[349]+1,"*"); *separators[350] = '\0';
    separators[351] = strstr(separators[350]+1,"*"); *separators[351] = '\0';
    separators[352] = strstr(separators[351]+1,"*"); *separators[352] = '\0';
    separators[353] = strstr(separators[352]+1,"*"); *separators[353] = '\0';
with:
Code:
for (i = 255;i <= 353;i++)
{
    separators[i] = strstr(separators[i - 1] + 1,"*"); *separators[i] = '\0';
}
--
Code:
ZeroMemory(&Text_File,sizeof(Text_File));
    Text_File = CreateFile("Position Variables.gtx",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,F  ILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NUL  L); /* Opens the program text file with read access. */
    if(Text_File==INVALID_HANDLE_VALUE){MessageBox(NUL  L,"Could Not Open File - Positions Variables.gtx!","--- Alert: Serious Error ---",MB_ICONEXCLAMATION|MB_OK); PostQuitMessage (0); return;} //Checks that the text file is open.
    *file_size = GetFileSize(Text_File,NULL); // Gets the size of the char array needed to store the text from the file.
    Position_Variables_Text_File = new char[*file_size + 1]; //Creates that array.
    SetFilePointer(Text_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to read from to the start. */               
    ReadFile(Text_File,Position_Variables_Text_File,*f  ile_size,bytes,NULL); //Reads the file into the array.
    CloseHandle(Text_File); /* Closes position variables text file. */
You have several blocks like this. You should consider replacing repeated code with function calls. Consider replacing each of the code blocks where you read a file in with something like:
Code:
Position_Variables_Text_File = ReadEntireFile("Position Variables.gtx");
Input_Messages_File          = ReadEntireFile("Input Messages.gtx");
where you provide the ReadEntireFile() function.
--
Just those two suggestions alone should reduce your Init() function code to less than 5% of the original and make it far easier to spot memory leaks.
--
A simple search of your code shows you have 12 new[]s and only 11 delete[]s.

Last edited by anonytmouse; 07-08-2004 at 02:59 PM.
anonytmouse is offline   Reply With Quote
Old 07-09-2004, 09:54 AM   #4
Self-Taught Programmer
 
CodeHacker's Avatar
 
Join Date: Jul 2004
Posts: 12
Thanks a lot, anonytmouse and salem! I'll remove that extra new command, and replace all that code with for loops and function calls!
__________________
--- I think I think, therefore I might be ---

Why call myself the Code Hacker when I'm only a beginner? Because every day I log onto my PC and hack 'n' slash my way through line after line of my mixed up code, trying to make it work. And failing miserably.
CodeHacker is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting number Leslie C Programming 8 05-20-2009 04:23 AM
To find the memory leaks without using any tools asadullah C Programming 2 05-12-2008 07:54 AM
c++ linking problem for x11 kron Linux Programming 1 11-19-2004 10:18 AM
dynamic memory deletion via function starkhorn C++ Programming 4 08-25-2004 09:11 AM
Manipulating the Windows Clipboard Johno Windows Programming 2 10-01-2002 09:37 AM


All times are GMT -6. The time now is 09:26 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22