Problem : Build a program that reads two strings from the keyboard and generates a third string which consists of combining two strings in such a way that the characters of the first string are placed in odd positions while the characters of the second string in even positions. The length of the new string will be twice the length of the smaller string. Display all three strings on the screen.
My solution : (I've code something, but it gives me error. Can anyone show me where is the problem?)
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100], str2[100], str3[100];
int i=0;
int j;
int p;
printf("Give string 1: \n");
gets(str1);
printf("Give string 2: \n");
gets(str2);
if(strlen(str1)<strlen(str2))
p=strlen(str1);
else
p=strlen(str2);
j=0;
for(i=0; i<p*2; i++){
if(i%2==0)
str3[i]=str2[j];
else{
str3[i]=str1[j];
j++; }
}
printf("\n String 3 is : %d");
printf("\n String 2 is : %d");
printf("\n String 1 is : %d");
return 0;
}