Friday, September 23, 2011

A program to concatenate 2 strings

#include<stdio.h>
main()
{
char str1[40],str2[40];
int pos,count1,count2;

printf("\n Enter the first string: ");
scanf("%s",&str1); /*enter string 1*/

printf("\n Enter the second string: ");
scanf("%s",&str2); /*enter string 2*/

for(count1=0;str1[count1]!='\0';count1++)
{
;
}
pos=count1;
for(count1=pos,count2=0;str2[count2]!='\0';count1++)
{
str1[count1]=str2[count2++];
}
str1[count1]='\0';
printf("\n Concatenated string is %s",str1); /*print result*/
}

No comments:

Post a Comment