Shares
facebook sharing button Share
twitter sharing button Tweet
email sharing button Email
linkedin sharing button Share
reddit sharing button Share
tumblr sharing button Share
blogger sharing button Share
print sharing button Print
skype sharing button Share
sms sharing button Share
whatsapp sharing button Share
arrow_left sharing button
arrow_right sharing button

C and C++ strncat() - String Concatenate n Characters

<<Previous

Next >>




strcmp() - String Compare        strcpy() - String Copy        strcat() - String Concatenate




C Programming - strncat Syntax

strncat function is used to concatenate the specified portion of one string at the end of another string.

Syntax:
	char *strncat ( char *dest, const char *src, size_t number );

The above statement shows that the particular portion of source string is appended at the end of destination string.

For example:

	strncat(str2, str1, 4) ----- first 4 characters of str1 is appended at the end of str2.

Example program using strlen() in C Programming

#include<stdio.h>

#include<string.h>


main()
{
  char first[] = "SPRING";
  char second[] = "WELCOME";
  char result;

  printf(" The first string is %s ",first);
  printf(" \n The second string is %s ",second);

  result = strncat(second,first,4);
  printf(" \n Concatenated String is %s = ",result);
  return(0);
}

Output:

The first string is SPRING
The second string is WELCOME
Concatenated String is WELCOME SPRI

strlen() - String Length strlwr() - String Lower       

strncmp() - String n Compare        strncpy() - String n Copy






<< Previous

Next >>




strcat() - String Concatenation        strcmp() - String Compare


strcpy() - String Copy        strlen() - String Length














C and C++ strncat() - String Concatenate n Characters

<<Previous

Next >>




strcmp() - String Compare        strcpy() - String Copy        strcat() - String Concatenate




C Programming - strncat Syntax

strncat function is used to concatenate the specified portion of one string at the end of another string.

Syntax:
	char *strncat ( char *dest, const char *src, size_t number );

The above statement shows that the particular portion of source string is appended at the end of destination string.

For example:

	strncat(str2, str1, 4) ----- first 4 characters of str1 is appended at the end of str2.

Example program using strlen() in C Programming

#include<stdio.h>

#include<string.h>


main()
{
  char first[] = "SPRING";
  char second[] = "WELCOME";
  char result;

  printf(" The first string is %s ",first);
  printf(" \n The second string is %s ",second);

  result = strncat(second,first,4);
  printf(" \n Concatenated String is %s = ",result);
  return(0);
}

Output:

The first string is SPRING
The second string is WELCOME
Concatenated String is WELCOME SPRI

strlen() - String Length strlwr() - String Lower       

strncmp() - String n Compare        strncpy() - String n Copy






<< Previous

Next >>






strncat() - String n Concatenation        strlwr() - String Lower       

strncmp() - String n Compare       strncpy() - String n Copy