Monday, 19 October 2015

C program to concatnate 2 strings

#include<stdio.h>
#include<conio.h>
void main()
{
char st1[15],st2[30];
clrscr();
printf("\n enter 2 strings :");
gets(st1);
gets(st2);
strcat(st2,st1);
printf("\n concentated string is :");
puts(st2);
getch();
}


                                                                                  OR       


#include<stdio.h>
#include<conio.h>
void main()
{
char st1[100],st2[100],st3[100];
int i=0,j=0;
clrscr();
printf("\n enter 1st string:");
gets(st1);
printf("\n enter 2nd string :");
gets(st2);
while(st1[i]!='\0')
{
        st3[j]=st1[i];
        i++;
        j++;

 }
i=0;
while(st2[i]!='\0')
{
        st3[j]=st2[i];
        i++;
        j++;
 }
printf("\n concatnated string is :");
puts(st3);
getch();
}


No comments:

Post a Comment