Name
strncat
Synopsis
Appends a number of characters from one string to another
#include <string.h> char *strncat( char * restricts1, const char * restricts2, size_tn);
The strncat() function
copies up to n characters of the string
addressed by the second pointer argument,
s2, to the location following the string
addressed by the first pointer, s1. The
first character of s2 is copied over the
null character that terminates the string addressed by
s1. The function returns the value of its
first argument, which points to the resulting string. The locations
that strncat() reads from and
writes to must not overlap.
Unlike strcat(), strncat() has a third parameter,
n, to limit the length of the string
written. The strncat() function
stops copying when it has copied n
characters, or when it reaches a terminating null character in the
source string, whichever occurs first. In either case, strncat() appends a null character to the
concatenated string addressed by s1. The
string’s length thus increases by at most
n characters.
Example
See the example for strcspn() in this
chapter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access