Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Functions and Pointers
  5. Built-in functions
  6. Concate n Chars

Concate n Chars

Use of strncat( ) function

#include<stdio.h>
#include<string.h>
int main()
{
	char src[50];
	char dest[50];
	int n;
	puts("Enter string1:");
	gets(src);
	puts("Enter string2:");
	gets(dest);
	puts("Enter the number of characters to copy");
	scanf("%d",&n);
	puts("strings are:");
	puts(src);
	puts(dest);
	strncat(dest,src,n);
	puts("After Concatenation :");
	puts(dest);
	return 0;
}

Output

Enter string1:
Welcome
Enter string2:
all
Enter the number of characters to copy
3
strings are:
Welcome
all
After Concatenation :
allWel

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments