Sunday, April 28, 2013

strncat()

This function concatenates n characters of source string in the target string.


syntax:

strncat("target_string","source_string",no_of_character);

example:

source="book"
target="face"
strncat(target,source,3);
[Here, source string(i.e. book) first 3 characters is add at the end of target string(i.e. face). Hence now value of target string(i.e. face) is "faceboo".

illustrate strcat() in C program:


/*c program for strncat() function illustrate*/
#include<stdio.h>
int main()
{
 char source[40],target[40];
 printf("Enter source string : ");
 gets(source);
 printf("Enter target string : ");
 gets(target);
 strncat(target,source,3);
 printf("\nTarget:%s \nSource:%s",target,source);
 getch();
 return 0;
}

The output of above program would be:


Output of strncat() function used in C program
Figure: Screen shot for illustrate strncat() function C program


Related program:
  1. List of standard library function
  2. strlen()
  3. strcpy()
  4. strncpy()
  5. strcat()

No comments:

Post a Comment