27 December 2011

C Program to Concatenate Two string

Leave a Comment

Program to Concatenate Two string








#include<stdio.h>

void main()
{
char a[10],b[10],c[20],d;
int i=0,j,k;

//first string
printf("enter the 1st string :");
gets(a);

//second string
printf("enter the 2nd string :" );
gets(b);

//storing first string in temporary variable
for(k=0;a[k]!='\0';k++)
c[i++]=a[k];

printf("do you want to enter space between words y/n :");
scanf("%c",&d);
if(d=='y')
{
c[i++] = ' ';
//concatenating second string with first string
for(j=0;b[j]!='\0';j++)
c[i++] = b[j];
}
else
{
for(j=0;b[j]!='\0';j++)
c[i++] = b[j];
}
c[i++] = '\0';

//printing the concatenated string
for(i = 0;c[i]!='\0';i++)
printf("%c",c[i]);
}

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

0 comments:

Post a Comment