20_10

Write a C code to concatenate two strings.

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:

C code to concatenate two strings


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...