Code: Select all
char *substr(char *str,int st,int len)
{
int i,j=0,l;
char *s;
l = strlen(str);
if(len > 0)
s = (char *)malloc(100);
else
return("");
if(l < abs(st))
return("");
if(st == 0)
st = 1;
if(st < 0)
st = st + l + 1;
for(i=st-1; i<st+len-1; i++)
{
s[j] = str[i];
j++;
}
s[j] = '\0';
return(s);
}
One idea that I've had, as yet untested, is to pass a VarChar stage variable as an additional (char *) argument, and try to put the result there instead of allocating new storage.
Any other suggestions?
TIA