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:
Related program:
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:
Figure: Screen shot for illustrate strncat() function C program |
Related program:
- List of standard library function
- strlen()
- strcpy()
- strncpy()
- strcat()
Comments
Post a Comment