strncat, wcsncat, _mbsncat
Append characters of a string.
char*strncat(char*strDest,constchar*strSource,size_tcount**);**
wchar_t*wcsncat(wchar_t*strDest,constwchar_t*strSource,size_tcount**);**
unsignedchar*_mbsncat(unsignedchar*strDest,constunsignedchar*strSource,size_tcount**);**
Routine | Required Header | Compatibility |
strncat | <string.h> | ANSI, Win 95, Win NT |
wcsncat | <string.h> or <wchar.h> | ANSI, Win 95, Win NT |
_mbsncat | <mbstring.h> | Win 95, Win NT |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB | Single thread static library, retail version |
LIBCMT.LIB | Multithread static library, retail version |
MSVCRT.LIB | Import library for MSVCRT.DLL, retail version |
Return Value
Each of these functions returns a pointer to the destination string. No return value is reserved to indicate an error.
Parameters
strDest
Null-terminated destination string
strSource
Null-terminated source string
count
Number of characters to append
Remarks
The strncat function appends, at most, the first count characters of strSource to strDest. The initial character of strSource overwrites the terminating null character of strDest. If a null character appears in strSource before count characters are appended, strncat appends all characters from strSource, up to the null character. If count is greater than the length of strSource, the length of strSource is used in place of count. The resulting string is terminated with a null character. If copying takes place between strings that overlap, the behavior is undefined.
wcsncat and _mbsncat are wide-character and multibyte-character versions of strncat. The string arguments and return value of wcsncat are wide-character strings; those of _mbsncat are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine | _UNICODE & _MBCS Not Defined | _MBCS Defined | _UNICODE Defined |
_tcsncat | strncat | _mbsnbcat | wcsncat |
Example
/* STRNCAT.C */
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80] = "This is the initial string!";
char suffix[] = " extra text to add to the string...";
/* Combine strings with no more than 19 characters of suffix: */
printf( "Before: %s\n", string );
strncat( string, suffix, 19 );
printf( "After: %s\n", string );
}
Output
Before: This is the initial string!
After: This is the initial string! extra text to add
See Also _mbsnbcat, strcat, strcmp, strcpy, strncmp, strncpy, _strnicmp, strrchr, _strset, strspn