I'm not used to getting this deep in c++, but all these pointers are making my brain boil. I'm trying to get a str_replace working
VOID str_replace(PCHAR Dest, PCHAR Find, PCHAR Replace) {
PCHAR New=(char *)malloc(sizeof(CHAR)*MAX_STRING);
PCHAR Found = Dest;
PCHAR Temp = Dest;
strcpy(New,"");
while(strstr(Temp,Find))
{
Found = strstr(Temp,Find);
strncpy(&New[strlen(New)], Temp, Found - Temp);
strcat(New,Replace);
Temp = Found + strlen(Find);
}
strcat(New,Temp);
strcpy(Dest,New);
}
CHAR is just a char, PCHAR is just a pointer to a char, and MAX_STRING is 2048. i've tried a dozen diff things and I thought I finally had it with this routine above but it crashed on "while(strstr(Temp,Find))" after it had been running for about a minute, probably several thousand executions of the routine.
I know it's vague but can anyone point me in the right direction or explain what the hell i'm doing wrong. Do I need to destroy the memory at "New"?