cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstring (string.h) : strncat
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstring (string.h)
functions:
· memchr
· memcmp
· memcpy
· memmove
· memset
· strcat
· strchr
· strcmp
· strcoll
· strcpy
· strcspn
· strerror
· strlen
· strncat
· strncmp
· strncpy
· strpbrk
· strrchr
· strspn
· strstr
· strtok
· strxfrm
macros:
· NULL
types:
· size_t

-

strncat function
char * strncat ( char * destination, char * source, size_t num );
<cstring>

Append characters from string

Appends the first num characters of source to destination, plus a terminating null-character. If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.

Parameters

destination
Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string, including the additional null-character.
source
C string to be appended.
num
Maximum number of characters to be appended.

Return Value

destination is returned.

Example

/* strncat example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str1[20];
  char str2[20];
  strcpy (str1,"To be ");
  strcpy (str2,"or not to be");
  strncat (str1, str2, 6);
  puts (str1);
  return 0;
}

Output:


To be or not

See also

strcat Concatenate strings (function)
strncpy Copy characters from string (function)
memcpy Copy block of memory (function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us