Mail Archives: djgpp/1998/03/19/16:11:38
>rpinnell.at.characato.ucsm.edu.pe wrote:
>> void mstrcat(char *s,char *t)
>> {
>> while(*s++ != '\0')
>> ;
>> s--;
>> while((*s++ = *t++) != '\0')
>> ;
>> }
>>
Terry <iceman.at.ipass.net> replied:
>Basically, you have defined ms1 to be only 5 characters long. In
>your subroutine you then try to append another six characters. Well,
>the first string is not automatically adjusted. You might want to
>return another string from your subroutine like this.
>
>char * mstrcat(char *s, char *t)
>{
> char *s2;
> s2 = (char *) malloc(strlen(s)+strlen(t)+1); /* Extra byte for EOS */
> strcpy(s2,s);
> strcat(s2,t);
> return s2;
>}
On the other hand, he could have used realloc and preserved the form of his
original function.
s = (char *)realloc ...
--Jeff
- Raw text -