M
madhur
Hello
I have a function which is defined as follows:
char* strcut(char *str,char *cut)
{
char *newstr;
int i=0;
newstr=malloc(50);
strcpy(newstr,str);
while(newstr==cut)
++i;
return(newstr+i+1);
}
In this function, I return a pointer to a char in the string newstr. Since
the newstr was
allocated dynamically, howcan I free this memory after I have used up the
pointer outside
of the function since "newstr" will get out of scope after the return.
Madhur Ahuja
India
I have a function which is defined as follows:
char* strcut(char *str,char *cut)
{
char *newstr;
int i=0;
newstr=malloc(50);
strcpy(newstr,str);
while(newstr==cut)
++i;
return(newstr+i+1);
}
In this function, I return a pointer to a char in the string newstr. Since
the newstr was
allocated dynamically, howcan I free this memory after I have used up the
pointer outside
of the function since "newstr" will get out of scope after the return.
Madhur Ahuja
India