thank you all for replies, it works now
thank you all for replies, it works now
Minor thoughts and nitpicks.
> char *my_strcat(char *a, char *b)
Granted this is a custom strcat, but the signature doesn't match strcat. In particular, the second argument does not need to be modifiable and best practice would be to make it const to avoid inadvertent changes.
> while (*a++ != '\0');
I'm not a huge fan of directly modifying a parameter, especially when the interface of the function returns the parameter unchanged. Also, while I'll contradict myself immediately, one-liner statements with a lot happening are more difficult to wrap your head around as well as debug.
> *a = '\0';
This is unnecessary if you copy it in your loop.
Here's an example of a standard-conforming strcat for comparison purposes:
Code:char *strcat(char * restrict dst, const char * restrict src) { char *p = dst; /* Find the terminating null character in dst */ while (*p) { ++p; } /* Copy from the null to append src */ while (*p++ = *src++) ; return dst; }
My best code is written with the delete key.