How to fix strcpy so that it detects overlapping strings
In an interview, I was asked to write an implementation of strcpy and then fix it so that it properly handles overlapping strings. My implementation is below and it is very naive. How do I fix it so that: It detects overlapping strings and after detecting, how do we deal with the overlap and proceed? char* my_strcpy(char *a, char *b) { if (a == NULL || b == NULL) { return NULL; } if (a > b) { //we have an overlap? return NULL; } char *n = a; while (*b != '\0') { *a = *b; a++; b++; } *a = '\0'; return n; } int main(int argc, char *argv[]) { char str1[] = "wazzupdude"; char *after_cpy = my