#include <iostream>
using namespace std;
#include <string>
using std::string;
using std::getline;
int main ()
{
char string1[256];
char string2[256] ;
cout << "\nPlease enter the first array string: \n"<<endl;
gets (string1);
cout << "\nPlease enter the second array string: \n"<<endl;
gets (string2);
int length1 = strlen( string1 );
int length2 = strlen( string2 );
if ( ( strlen( string1 )) > ( strlen( string2 )) )
{
for ( int i = 0; i < length2; i++ )
{
cout<<" "<< *(string1 + i)<< " " << *( string2 +i);
}
}
if ( ( strlen( string1 )) < ( strlen( string2 )) )
{
for ( int j = 0; j < length2; j++ )
{
cout<<" "<< *(string1 + j) << " " << *( string2 +j);
}
}
if ( ( strlen( string1 )) == ( strlen( string2 )) )
{
for ( int k = 0; k < length2; k++ )
{
cout<<" "<< *(string1 + k) << " " << *( string2 +k);
}
}
return 0;
}
basically what i want as output is
for example if string1 is : hello
and string2 is : bye
the output should be : h b e y l e l o
this program basically does what i want it to do
but.
but the thing is that say the string1 is longer than string 2
fir the same example
it prints something like this
: h b e y l e l & o &
where & is a garbage value
how can i get rid of those garbage values