I implemented strcat function and when just playing around i used my function and started comparing with the standard string function strcat but i found an issue regarding the output of my_strcat and strcat. In my_strcat "programming" is printed twice while in strcat it is just printed once which is the expected behavior, but in case of my_strcat why is "programming displayed twice".
Things i tried: After while loop i put *dest++ = '\0' even then "programming" gets displayed twice. Am using linux system for programming and gcc.
o/p:
strcat:Pl_z� programming
my_strcat:Pl_z� programming programming
char *my_strcat(char *dest, const char *src) {
char *dst = dest;
while(*dest!= '\0')
dest++;
while(*dest++ = *src++)
;
return dst;
}
int main(int argc, char **argv) {
// char string1[25] = "C";
char string1[25];
char string2[] = " programming " ;
printf(" strcat:%s\n",strcat(string1, string2));
printf(" my_strcat:%s\n",my_strcat(string1, string2));
}