why does this cause a break in VS, I assume its because the pointer __array_buffer seems to be dealloc after update_typeArray finishes round about the third call but not always. I have no clue why. pleas help me (this is not the entire file, but the rest is mostly commented out and has no affect) this does not happen if I make update_typeArray a char * and __array_buffer = the return(return would be the pointer of __array_buffer passed in param). I would do that but I was hoping for overloading. 何でなの。please someone help me.
#include <iostream>
#include <Windows.h>
#include <thread>
#include <chrono>
#include <cmath>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <conio.h>
//winigga stuff
# define VT100_WinAPI \
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);\
DWORD dwMode = 0;\
GetConsoleMode(hOut, &dwMode);\
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;\
SetConsoleMode(hOut, dwMode);
//////////////////////////////////////////////////////////////////
/*
Increment before use if index is 0 from init, (Char)array must contain a single value, and will recive '/0'.
Size of array is calculated by overloads input type and index (with null terminater taken in to account).
*/
void update_typeArray(char * char_array, int index, char input)
{
char * new_array = (char*)malloc(sizeof(char)*(index + 1));//+1 cause string
for (int i = 0; i <= index; i++)
{
if (i < index)
{
new_array[i] = char_array[i];
}
if (i == index)
{
new_array[i] = '\0';//'\000' cause string
}
}
free(char_array);
new_array[index - 1] = input;
char_array = (char*)malloc(sizeof(char)*(index + 1));//+1 cause string
for (int i = 0; i <= index; i++)
{
if (i < index)
{
char_array[i] = new_array[i];
}
if (i == index)
{
char_array[i] = '\0';//'\000' cause string
}
}
free(new_array);
}
/*
Increment before use if index is 0 from init, (Int)array must contain a single value.
Size of array is calculated by overloads input type and index.
*/
//Debug
/*
void update_typeArray(int * int_array, int index, int input)
{
int * new_array = (int*)malloc(sizeof(int)*(index));
for (int i = 0; i < index; i++)
{
new_array[i] = int_array[i];
}
free(int_array);
new_array[index - 1] = input;
int_array = (int*)malloc(sizeof(int)*(index));
for (int i = 0; i < index; i++)
{
int_array[i] = new_array[i];
}
free(new_array);
}
*/
int main()
{
VT100_WinAPI
while (!(GetKeyState(0x1B) & 0x8000))
{
if (_kbhit()||true)
{
char * __array_buffer = (char*)malloc(sizeof(char)); __array_buffer[0] = '\0';
int index = 0;
bool chbuff_cyc = true;
int size;
while (chbuff_cyc)
{
char j[] = "reta";
char __char_buffer = j[index];//_getch();
if (__char_buffer == '\0')
{
chbuff_cyc = false;
size = index;
}
else
{
++index;
update_typeArray(__array_buffer, index, __char_buffer);
}
}
if (size > 0)
{
bool * blist = (bool*)malloc(size);
//-----------|searchCommand (Start)|------------
if (size == StringSize("a"))
{
compare_typeArray(__array_buffer,"a",size,blist);
if(checkem(blist,size,and))
{
_putch('a');
}
}
//-----------|searchCommand (End)|------------
free(blist);
}
free(__array_buffer);
}
}
return 0;
}