#include <iostream>
#include <string.h>
usingnamespace std ;
//concatenate function
char* join(constchar* A, constchar* B)
{
//declare variable 8+1 characters
char join[9];
strcpy(join,A);
strcat(join,B);
cout << join <<'\n';
//join both caracthers
char* str = join;
return str;
//return the string
}
//char* joinb(const char*, const char*) ;
int main() {
//call the function
cout << join("alpha","bet") << endl ;
// cout << joinb("duck","soup") << endl ;
return 0 ;
}
The first cout in the join function gives me the right result, but when setting the return i get the address (I think it is), or no memory is correctly allocated. Any solution to these?
@Thomas1965 - Line 8: you have the comparison reversed. I would presume you intended to return without doing anything if the combined size was larger than the size of the output buffer.