C program for concatenate two strings or append string with another string.
1) Using library strcat() function
2) Without using library function strcat()
1) Using library strcat() function
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100], str2[100];
printf("Enter String-1 :");
gets(str1);
printf("Enter String-2 :");
gets(str2);
/* Standard library function of header file string.h */
strcat(str1,str2);
printf("\nAfter Concatenate Operation str1 = %s",str1);
return 0;
}
#include<stdio.h>
int main()
{
char str1[100],str2[100];
int i=0,j=0;
printf("Enter String-1 : ");
gets(str1);
printf("Enter String-2 : ");
gets(str2);
while( str1[i] != '\0' )
i++;
while( str2[j] != '\0' )
{
str1[i] = str2[j];
j++;
i++;
}
str1[i] = '\0';
printf("\n\nAfter Concatenate Operation str1 = %s",str1);
return 0;
}
0 comments :
Post a Comment