I challenge you to a duel at dawn. :-)
Code:
char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
You should reread the entire documentation.
If the array pointed to by s2 is a string that is shorter than n bytes, null bytes shall be appended to the copy...
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.
Code:
char s1[50]; /* 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 */
s1 now contains the first ten chars of s2 and is not null terminated.
If you had read the entire doc you would have found this:
If there is no null byte in the first n bytes of the array pointed to by s2, the result is not null-terminated.
I'm sure you would agree that there is no null byte in the first ten characters of s2 above.
Code:
strncpy ( new_src, src, (size_t)(found - src) );
Again, there is no null in the first n bytes of src.
This would work:
Code:
char s1[50];
char s2[] = "test";
strncpy(s1,s2,50); /* = strcpy(s1,s2); */
but is a pointless exercise.
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.