Thursday, 20 September 2012

program to concatenate strings


This program concatenates strings, for example if the first string is "c " and second string is "program" then on concatenating these two strings we get the string "c program". To concatenate two strings we use strcat function of string.h, to concatenate without using library function see another code below which uses pointers.

C code

#include<stdio.h>
#include<conio.h>
#include<string.h>
 
main()
{
   char a[100], b[100];
 
   printf("Enter the first string\n");
   gets(a);
 
   printf("Enter the second string\n");
   gets(b);
 
   strcat(a,b);
 
   printf("String obtained on concatenation is %s\n",a);
 
   getch();
   return 0;
}

No comments:

Post a Comment