(C++) CPP Programs - 21

Friday, December 14, 2007

21. Write a C program to read two strings and concatenate them (without using library functions). Output the string along with suitable messages.

/* Concatenation of 2 strings*/

#include
#include

void main()
{
char str1[67],str2[98],str[56];
int i,j;
clrscr();

printf("\nEnter string1\n");
gets(str1);

printf("\nEnter string2\n");
gets(str2);

printf("\nThe string1 is\n");
puts(str1);

printf("\nThe string2 is\n");
puts(str2);

i=0;j=0;

while(str1[i]!='\0')
{
str[j]=str1[i];
i++;
j++;
}

str[j]=2;
j++;
i=0;

while(str2[i]!='\0')
{
str[j]=str2[i];
i++;
j++;
}
str[j]='\0';

printf("\nThe new string after concatenation is\n");
puts(str);

getch();
}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP