To concatenate two strings in c without using strcat function
#include<stdio.h>
#include<conio.h>
void main( )
{
char str1[50],str2[50];
int i,j;
clrscr( );
printf("\nEnter the first string :");
gets(str1);
printf("\nEnter the second string :");
gets(str2);
/*move to the end of the first string*/
i=0;
while(str1[i]!='\0')
{
i=i+1;
}
/*Copy second string into first string*/
j=0;
while(str2[j]!='\0')
{
str1[i]=str2[j];
i=i+1;
j=j+1;
}
str1[i]='\0';
printf("\nResult : %s",str1);
getch( );
}
Comments
Post a Comment