String Concatenation in C
#include<stdio.h>
#include<string.h>
void main()
{
char str1[10],str2[10],str[20];
int i=0,j=0,k=0;
clrscr();
printf ("enter the two strings\n");
gets (str1);
gets (str2);
while (str1[i]!='\0')
{
str[k++]=str1[i++];
}
while (str2[j]!='\0')
{
str[k++]=str2[j++];
}
str[k]='\0';
printf("The concatenated string is:");
puts (str);
getch();
}
#include<stdio.h>
#include<string.h>
void main()
{
char str1[10],str2[10],str[20];
int i=0,j=0,k=0;
clrscr();
printf ("enter the two strings\n");
gets (str1);
gets (str2);
while (str1[i]!='\0')
{
str[k++]=str1[i++];
}
while (str2[j]!='\0')
{
str[k++]=str2[j++];
}
str[k]='\0';
printf("The concatenated string is:");
puts (str);
getch();
}
No comments:
Post a Comment