Looking at this question that has just been asked: http://stackoverflow.com/questions/2231317/inconveniences-of-pointers-to-static-variables would doing something like this be considered bad practice, then?
char* strpart(char* string, int start, int count)
{
char* strtemp;
int i = 0; int j = 0;
int strL = strlen(string);
if ( count == 0 )
{
count = strL;
}
strtemp = (char*) calloc((count + 1), sizeof(char));
for ( i = start; i < (start+count); i++ )
{
strtemp[j] = string[i];
j++;
}
return strtemp;
}
Sorry it's written quickly, but the basic principle is - when NOT using a static buffer inside a function is it bad practice to assign memory inside a function? I assume so because it wouldn't be freed, would it? Thought I ought to ask though.