Strncat () function in C

Char * strncat (char * dest, const char * src, size_t n) append (string), pointed to by src, at the end of the string pointed to by dest, with a length of up to n characters.

Char * strncat (char * dest, const char * src, size_t n) append (string), pointed to by src, at the end of the string pointed to by dest, with a length of up to n characters.

Declaring strncat () function in C

Here is the declaration for strncat () in C:

 char * strncat ( char * dest , const char * src , size_t n ) 

Parameters

dest - This is the pointer to the destination array, which should contain a string, and should be large enough to contain the result string after being concatenated (including additional null characters).

src - This is the string to be appended at the end (append).

n - This is the maximum number of characters to be appended.

Returns the value

This function returns a pointer to the dest result string.

For example

The following C program illustrates the usage of strncat () in C:

 #include #include int main () { char src [ 50 ], dest [ 50 ]; strcpy ( src , "Day la chuoi source (chuoi src)" ); strcpy ( dest , "Day la chuoi destination (chuoi dest) " ); strncat ( dest , src , 15 ); printf ( "Sau khi thuc hien ham strncat, chuoi dest co dang:n|%s|" , dest ); return ( 0 ); } 

Compiling and running the above C program will result:

Strncat () function in C Picture 1Strncat () function in C Picture 1

According to Tutorialspoint

Previous article: strcat function in C

Next lesson: strchr () function in C

5 ★ | 1 Vote