I'm trying to code a strcat with pointers:
Code:
#include <stdio.h>
void Strcat(char* s, char* t)
{
while(*s++ != '\0')
;
while( (*s++ = *t++) )
;
}
int main(void)
{
char* s1 = "Thames";
char* s2 = "Thames";
Strcat(s1, s2);
printf("The concatenated string is %s\n", s1);
return 0;
}
debug
Code:
gdb -q strcat2
Reading symbols from /home/ethereal/C/Strings/strcat2...done.
(gdb) break 5
Breakpoint 1 at 0x400500: file strcat2.c, line 5.
(gdb) break 7
Breakpoint 2 at 0x400516: file strcat2.c, line 7.
(gdb) run
Starting program: /home/ethereal/C/Strings/strcat2
Breakpoint 1, Strcat (s=0x400680 "Thames", t=0x400680 "Thames") at strcat2.c:5
5 while(*s++ != '\0')
(gdb) c
Continuing.
Breakpoint 2, Strcat (s=0x400687 "", t=0x400680 "Thames") at strcat2.c:7
7 while( (*s++ = *t++) )
(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400522 in Strcat (s=0x400687 "", t=0x400680 "Thames") at strcat2.c:7
7 while( (*s++ = *t++) )