In this tutorial, we are going to share about the strncat()
function in c programming language strncat()
function is used for concatenation of two strings.
Here is the code syntax to use the strncat()
function in the c programs.
1 | char *strncat(char *str1, const char *str2, size_t n) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdio.h> #include <string.h> int main () { char str1[50], str2[50]; //destination string strcpy(str1, "This is my initial string"); //source string strcpy(str2, ", add this"); //displaying destination string printf("String after concatenation: %s\n", strncat(str1, str2, 5)); // this should be same as return value of strncat() printf("Destination String str1: %s", str1); return 0; } |
String after concatenation: This is my initial string, add
Destination String str1: This is my initial string, add
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.