I can't understand why this doesn't work,
but when i enable char *s=s1 and use s wherever s1 is used it returns the correct output.

char *mystrncat(char *s1,const char *s2, size_t n )
//  char *s=s1;

    while(n!=0 && (*s1++=*s2++)!='\0')


    return s1;


What does s1 point to on line 15?? It points to the end of the string, not to the beginning and that's why it doesn't work. You can't change the value of the poiter if you intend to use it again. Line 15 needs to return s, not s1, because s is pointing to the beginning of the string.