write a c program to concatenate two strings,write a c program to concatenate two strings using strcat,c program to concatenate two strings using library functions,c program to concatenate two strings using functions,write a program to concatenate two strings in c
Write a c program to concatenate two strings
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[10]="Lot";
char s2[10]="us";
strcat(s1,s2);
printf("Concatenated string is %s",s1);
getch();
}
Output:
Write a c program to concatenate two strings without using built-in function
#include<stdio.h>
#include<conio.h>
#include<string.h>
void concatenate(char str1[],char str2[]);
void main()
{
char s1[30],s2[30];
clrscr();
printf("Enter the first string: ");
gets(s1);
printf("Enter the second string: ");
gets(s2);
concatenate(s1,s2); //function
call
printf("Concatenated string: %s",s1);
getch();
}
void concatenate(char str1[],char str2[])
{
int l1,l2,i;
l1=strlen(str1);
l2=strlen(str2);
for(i=0;i<l2;i++)
str1[l1+i]=str2[i];
str1[l1+l2]='\0';
}
Output:
Enter the first string: Love
Enter the second string: Programming
Concatenated string: LoveProgramming
No comments: