Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strncat - Concatenate strings

&pagelevel(4)&pagelevel

Definition

#include <string.h>

char *strncat(char *s1, const char *s2, size_t n);

strncat appends a maximum of n characters from string s2 to the end of string s1 and returns a pointer to s1.

The null byte (\0) at the end of string s1 is overwritten by the first character of string s2.

If string s2 contains less than n characters, only the characters from s2 are appended to s1.
If string s2 contains more than n characters, only the first n characters from s2 are appended to s1.

Return val.

Pointer to the result string.

strncat terminates the string with the null byte (\0).

Notes

Strings terminated with the null byte (\0) are expected as arguments.

strncat does not check whether s1 is large enough for the result!

The behavior is undefined if memory areas overlap.

Example

#include <string.h>
#include <stdio.h>
int main(void)
{
  char text1[BUFSIZ];
  char text2[BUFSIZ];
  int n;
  printf("Example of strncat - please enter 2 text lines and n!\n");
  if(scanf("%s %s %d", text1, text2, &n) == 3)
     printf("%s\n", strncat(text1, text2, n));
  return 0;
}

See also

strcat