From 7d749d11178a89912344083129ad4dadf7b8348d Mon Sep 17 00:00:00 2001 From: wolfwhocodes <40625914+wolfwhocodes@users.noreply.github.com> Date: Mon, 3 Dec 2018 23:38:26 +0530 Subject: [PATCH] Added a new string function called strncat (#23319) Brief description and example of the strncat function was given. --- guide/english/c/arrays-and-strings/index.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guide/english/c/arrays-and-strings/index.md b/guide/english/c/arrays-and-strings/index.md index 4151450cf0..5288559b62 100644 --- a/guide/english/c/arrays-and-strings/index.md +++ b/guide/english/c/arrays-and-strings/index.md @@ -192,6 +192,12 @@ if(!strcmp(first, second)){ ``` Notice the `!`, which is needed because this function returns 0 if they are the same. Placing the exclamation point here will make that comparison return true. +#### Concatenate number of characters to a string: `strncat` +`strncat` (from 'string number concatenate') concatenates a certain number of characters from the beginning of the second string to the end of first string. In this example, strncat will concatenate some characters from the second to the first string: +```C +strncat(char s1[], char s2[], int n); +``` + #### Compare 'n' bytes: `strncmp` `strncmp` compares two strings for 'n' characters. The integer value it returns is 0 if they are the same, but it will also return negative if the value of the first (by adding up characters) is less than the value of the second, and positive if the first is greater than the second. Take a look at an example of how this might be used: ```C