On 12 Sep 2003 06:44:30 -0700
(Jon) wrote:
> using Borland Compiler.
Doesn't matter, I hope, or this post is off-topic.
> x[32] = "this is a string"
>
> strcat(x,x)
> strcat(x,x)
>
> will produce "this is a stringthis is a stringthis is a stringthis is
> a stringt"
>
> but should produce "this is a stringthis is a stringthis is a
> stringthis is a string"
>
> does anyone know why the additional character from the beginning of
> the string is being appended at the end?
The arguments to strcat may not overlap. The way you call it leads to undefined
behaviour. Anything could happen.
> in addition does anyone know the source for the strcat function? I am
> curious as to how they did it.
www.gnu.org. Download the glibc source package. You'll see why the strings may
not overlap.
--
char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
c,k,0),x(c,k+=*s-c,s+1),*k)

x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh$%c","-34*1'.+(,03#;+,)/'///*");}