When using malloc or new to allocate an array of characters for a nul terminated string, you need to include one extra character for the terminating nul.
Replace this:
str3 = (char*) malloc(13);
with this:
str3 = (char*) malloc(count + 1);
or this:
str3 = new char[count + 1];
Don't forget to terminate the new string with a nul character.
Replace this:
for(j= 0; str2[j]!=NULL;j++,i++)
{
str3[i] = str2[j];
}
with this:
for(j=0; str2[j]!=0; j++,i++)
{
str3[i] = str2[j];
}
str3[i] = 0;
Now that the new string is nul terminated, you can replace this:
while(*str3)
{
cout<<*str3++;
}
with this:
cout << str3;
The following code tells me you tried something but it did not work.
The reason is the sizeof operator does not give you the length of a string but the size of the string pointer.