Source code:
//Write a C code to concatenate two strings
#include <stdio.h>
#include <string.h>
int main(){
char str1[20],str2[2];
printf("Enter 1st string:");
//Read String 1
scanf("%s", str1);
printf("Enter 2nd string:");
//Read String 2
scanf("%s", str2);
int i,j,temp;
i=j=0;
while (str1[i] != '\0')
i++;
for (j = 0; str2[j] != '\0'; i++, j++)
str1[i] = str2[j];
str1[i] = '\0';
printf("The concatenated output:%s",str1);
return 0;
}
Output:
No comments:
Post a Comment