I read a lot of questions here in SO and some other articles regarding the free () function in c, which frees up memory of unused variables. In my case, I have the following block of code.
char *injectStrAt(char *str, char *strToIn, int pos)
{
char *strC = malloc(strlen(str) + strlen(strToIn) + 1);
strncpy(strC, str, pos);
strC[pos] = '\0';
strcat(strC, strToIn);
strcat(strC, str + pos);
return strC;
}
The above function, which I use to input a string block into an array. I use mallocto create a new one char*. In the case above, do I need to do free(strC)? consulting services.
fSazy source
share