C program to Concatenate Two Strings Using While Loop
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
clrscr();
char Str1[100], Str2[100];
int i, j;
printf("\n Please Enter the First String : ");
gets(Str1);
printf("\n Please Enter the Second String : ");
gets(Str2);
i = 0;
while( Str1[i]!='\0')
{
i++;
}
j = 0;
while( Str2[j]!='\0')
{
Str1[i] = Str2[j];
i++;
j++;
}
Str1[i] = '\0';
printf("\n String after the Concatenate = %s", Str1);
return 0;
getch();
}
#include<conio.h>
#include<string.h>
int main()
{
clrscr();
char Str1[100], Str2[100];
int i, j;
printf("\n Please Enter the First String : ");
gets(Str1);
printf("\n Please Enter the Second String : ");
gets(Str2);
i = 0;
while( Str1[i]!='\0')
{
i++;
}
j = 0;
while( Str2[j]!='\0')
{
Str1[i] = Str2[j];
i++;
j++;
}
Str1[i] = '\0';
printf("\n String after the Concatenate = %s", Str1);
return 0;
getch();
}
C program to Concatenate Two Strings Using Functions
#include<stdio.h>
#include<conio.h>
#include<string.h>
void concatenate(char [], char []);
int main()
{
clrscr();
char Str1[100], Str2[100];
printf("\n Please Enter the First String : ");
gets(Str1);
printf("\n Please Enter the Second String : ");
gets(Str2);
concatenate(Str1, Str2);
printf("\n String after the Concatenate = %s", Str1);
return 0;
}
void concatenate(char s1[], char s2[])
{
int i, j;
i = 0;
while( s1[i]!='\0')
{
i++;
}
j = 0;
while( s2[j]!='\0')
{
s1[i] = s2[j];
i++;
j++;
}
s1[i] = '\0';
}
#include<conio.h>
#include<string.h>
void concatenate(char [], char []);
int main()
{
clrscr();
char Str1[100], Str2[100];
printf("\n Please Enter the First String : ");
gets(Str1);
printf("\n Please Enter the Second String : ");
gets(Str2);
concatenate(Str1, Str2);
printf("\n String after the Concatenate = %s", Str1);
return 0;
}
void concatenate(char s1[], char s2[])
{
int i, j;
i = 0;
while( s1[i]!='\0')
{
i++;
}
j = 0;
while( s2[j]!='\0')
{
s1[i] = s2[j];
i++;
j++;
}
s1[i] = '\0';
}
Run:
No comments:
Post a Comment