Original Post
Hi guys, I'm just trying to debug this function that truncates a function before an occurance of a character(inclusive of the character). For example, in the string "Testing one two three", truncate the string before the first occurance of the character ' '. The result would be "one two three". Anyway, I'm only an beginner/intermediate skilled programmer and thus I have come here for your help :). The problem i'm getting is related to malloc, it crashes at runtime with a "Unhandled exception at 0x77f75a58". The code is as follows:
EXPORT LPSTR PreTruncateChr(LPSTR lpszString, CHAR cScissors, WORD wNumber)
{
LPSTR lpszInput;
LPSTR lpszFinal = (LPSTR)malloc(sizeof(lpszString));
LPSTR lpszOutput;
WORD wCutSize = 0;
if (lpszFinal == NULL)
return NULL;
if (!wNumber)
return NULL;
for (WORD wLoop = 0; wLoop < wNumber; wLoop++)
lpszInput = strchr(lpszString, cScissors) + 1;
wCutSize = (WORD)(lpszString + strlen(lpszString) - lpszInput);
lpszOutput = (LPSTR)lpszFinal;
for (WORD wLoop = 0; wLoop < wCutSize; wLoop++, lpszInput++, lpszOutput++)
*lpszOutput = *lpszInput;
*lpszOutput = '\0';
return lpszFinal;
} All help is greatly appreciated.