0% found this document useful (0 votes)
24 views

String Merging

This document describes how to merge two strings into a third string by iterating through the characters of each input string and adding them alternately to the output string until all characters from both inputs have been used. It provides an example of merging the strings "abc" and "123" into the output string "a1b2c3" and includes sample C code to implement the string merging logic.

Uploaded by

Amar Sequeira
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

String Merging

This document describes how to merge two strings into a third string by iterating through the characters of each input string and adding them alternately to the output string until all characters from both inputs have been used. It provides an example of merging the strings "abc" and "123" into the output string "a1b2c3" and includes sample C code to implement the string merging logic.

Uploaded by

Amar Sequeira
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

String Merging

Str1= a b c Str2= 1 2 3

Str3= a 1 b 2 c 3
String Merging

Str1= a b c Str2= 1 2 3 4 5

Str3= a 1 b 2 c 3 4 5
String Merging

Str1= a b c Str2= 1 2 3

Str3= a 1 b 2 c 3 \0
Code
main()
{
int i=0,j=0,k=0; ch1 i
char ch1[10],ch2[10],ch3[20]; ch2 j
printf("enter the two String:"); ch3 k
scanf("%s%s",ch1,ch2);

while(ch1[i]!='\0'||ch2[j]!='\0')
{

if(ch1[i]!='\0')
    ch3[k++]=ch1[i++];

if(ch2[j]!='\0')
    ch3[k++]=ch2[j++];
}

ch3[k]='\0';
printf("The merge string is :%s\n",ch3);
}

You might also like