www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/19/16:11:38

From: zoey4pres AT aol DOT com (Zoey4Pres)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Pointers and DJGPP
Date: 19 Mar 1998 20:48:29 GMT
Lines: 33
Message-ID: <1998031920482900.PAA25149@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
Organization: AOL http://www.aol.com
References: <3510449E DOT AE294519 AT ipass DOT net>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019