//WAP in C to Concatenate strings using standard library functions
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
{
int len1, len2, i;
char string1[50],string2[50];
clrscr();
printf("Enter the first String\n");
gets(string1);
printf("\nEnter the second String\n");
gets(string2);
len1=strlen(string1); //calculating length of string1
len2=strlen(string2); //calculating length of string2
printf("\n\nString after concatenation is:\n ");
//code for string concatenation
for(i=0;i<=len2;i++)
{
string1[len1+i]=string2[i]; //concatenating string1 and string2
}
//OR
getch(); // for holding the console screen
}
clrscr();
printf("Enter the first String\n");
gets(string1);
printf("\nEnter the second String\n");
gets(string2);
len1=strlen(string1); //calculating length of string1
len2=strlen(string2); //calculating length of string2
printf("\n\nString after concatenation is:\n ");
for(i=0;i<=len2;i++)
{
string1[len1+i]=string2[i]; //concatenating string1 and string2
}
//OR
string1=strcat(string1,string2); // built-in library function
printf("%s",string1); //printing the concatenated stringgetch(); // for holding the console screen
}
No comments:
Post a Comment