C program for concatenation two strings without using library function

C program for concatenation two strings without using library function:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
#include<string.h>
void concat(char[],char[]);
main()
{
   char s1[50],s2[30];

   printf("Enter First String :");
   gets(s1);
   printf("\nEnter Second String :");
   gets(s2);

   concat(s1,s2);
   printf("\nConcatenation string is :%s",s1);
}
void concat(char s1[],char s2[])
{
   int i,j;
   i=strlen(s1);

   for(j=0;s2[j] != '\0';i++,j++)
    {
      s1[i] = s2[j];
    }
   s1[i]= '\0';
}

OUTPUT:

Enter First String :Baron

Enter Second String :Tuts

Concatenation string is :BaronTuts

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.