add string without using concat().c

#include<stdio.h>

#include<string.h>

 

void concat(char[], char[]);

 

int main()

{

   char s1[50], s2[30];

 

   printf("\nEnter String 1 : ");

   gets(s1);

   printf("\nEnter String 2 : ");

   gets(s2);

 

   concat(s1, s2);

 

   printf("\nConcated string is : %s", s1);

 

   return (0);

}

 

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 String 1 : Programming

Enter String 2 : Hub

Concated string is : ProgrammingHub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s