Best method to alloc memory for string and desalloc.
how the Best method to alloc memory for string and after desalloc.
Im using this:
Code:
void ClearStr ( char * pString )
{
*pString = '\0';
}
char *substr(const char *pstr, int start, int numchars)
{
char *pnew = malloc(numchars+1);
strncpy(pnew, pstr + start, numchars);
pnew[numchars] = '\0';
return pnew;
}
char *teste;
char *teste2;
teste = ReceiveComm();
teste2 = substr (teste, 1, 6);
ClearStr (teste);
this is executed all 5 minutes, for all long program be executed.