Name
strcat
Synopsis
Appends one string to another
#include <string.h> char *strcat( char * restricts1, const char * restricts2);
The strcat() function
copies 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
terminating null character of the string addressed by
s1.The function returns the value of its
first argument, which points to the concatenated string.
There is no limit to the number of characters strcat() may write before it encounters a
null character in the source string. It is up to you the programmer
to make sure that there is enough storage available at the
destination to accommodate the result. You should consider using
strncat() instead to reduce the
risk of buffer overflows. You must also make sure that the locations
that strcat() reads from and
writes to do not overlap.
Example
typedef struct { char lastname[32];
char firstname[32];
_Bool ismale;
} Name;
char displayname[80];
Name *newName = calloc( 1, sizeof(Name) );
/* ... check for calloc failure; read in the name parts ... */
strcpy( displayname, ( newName->ismale ? "Mr. " : "Ms. " ) );strcat( displayname, newName->firstname );
strcat( displayname, " " );
strcat( displayname, newName->lastname );
puts( displayname );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