Hi, I created a function which performs similarly to strcat().
Code:
#include<stdio.h>
#include<string.h>
char xstrcat(char *s,char *q,int x);
int main()
{
char a[]="Shabbir",b[]="Hussain";
char *c[50];
int x;
x=strlen(a);
xstrcat(a,b,x);
printf("\n\n%s\n\n",a);
return 0;
}
char xstrcat(char *s,char *q,int x)
{
int i;
for(i=0;i<=x;i++){
if(*s=='\0'){
*s=' ';
s++;
while(*q!='\0'){
*s=*q;
++s;
++q;
}
}
else{
++s;
}
}
*s='\0';
return 0;
}
I got the desired Output, but also something else.
Code:
shabbirhussain@shabbirhussain:~/c$ ./c
Shabbir Hussain
*** stack smashing detected ***: ./c terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7ead138]
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7ead0f0]
./c[0x8048495]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7dd6450]
./c[0x80483a1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:06 49660 /home/shabbirhussain/c/c
08049000-0804a000 rw-p 00000000 08:06 49660 /home/shabbirhussain/c/c
0804a000-0806b000 rw-p 0804a000 00:00 0 [heap]
b7dbf000-b7dc0000 rw-p b7dbf000 00:00 0
b7dc0000-b7f09000 r-xp 00000000 08:06 286938 /lib/tls/i686/cmov/libc-2.7.so
b7f09000-b7f0a000 r--p 00149000 08:06 286938 /lib/tls/i686/cmov/libc-2.7.so
b7f0a000-b7f0c000 rw-p 0014a000 08:06 286938 /lib/tls/i686/cmov/libc-2.7.so
b7f0c000-b7f0f000 rw-p b7f0c000 00:00 0
b7f16000-b7f20000 r-xp 00000000 08:06 269344 /lib/libgcc_s.so.1
b7f20000-b7f21000 rw-p 0000a000 08:06 269344 /lib/libgcc_s.so.1
b7f21000-b7f24000 rw-p b7f21000 00:00 0
b7f24000-b7f25000 r-xp b7f24000 00:00 0 [vdso]
b7f25000-b7f3f000 r-xp 00000000 08:06 269299 /lib/ld-2.7.so
b7f3f000-b7f41000 rw-p 00019000 08:06 269299 /lib/ld-2.7.so
bf8a6000-bf8bb000 rw-p bffeb000 00:00 0 [stack]
Aborted
Is there something wrong with the compiler? What does this whole thing mean?