O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connecting Strings (Concatenation)

Concatenation is the process of appending one string onto another. It's kind of like addition for words. To perform concatenation, you use the strncat() function:

strncat(string1, string2, length);

This function will append the value of string2 onto the end of string1. It will append up to length number of characters. This length value should correspond to the remaining space in string1. For example:

char string1[25] = "Mary had a ";
char string2[] = "little lamb.";
strncat(string1, string2, 13);

strn* Functions and Overflow

In earlier C standards, the available string functions were strcat(), strcpy(), and so forth. The problem with these functions is that they allowed for a buffer overflow, a serious ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required