I challenge you to a duel at dawn. :-)
You should reread the entire documentation.
char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
If string s2 is shorter that n bytes then we do not need to use strncpy we could just use strcpy. The whole idea of strncpy is that we want to copy only the first n bytes from s2.
If the array pointed to by s2 is a string that is shorter than n bytes, null bytes shall be appended to the copy...
s1 now contains the first ten chars of s2 and is not null terminated.
char s1; /* random data */
char s2 = "We want to copy the first 10 chars of s2";
strncpy(s1,s2,10); /* s2 is not shorter than n bytes */
If you had read the entire doc you would have found this:
I'm sure you would agree that there is no null byte in the first ten characters of s2 above.
If there is no null byte in the first n bytes of the array pointed to by s2, the result is not null-terminated.
Again, there is no null in the first n bytes of src.
strncpy ( new_src, src, (size_t)(found - src) );
This would work:
but is a pointless exercise.
char s2 = "test";
strncpy(s1,s2,50); /* = strcpy(s1,s2); */
or from MSDN:
If count is less than or equal to the length of strSource, a null character is not appended automatically to the copied string.