return an array doesn't work even with static

Hi all, for some reason when I call the function append(m[0], m[1]); it gives my an error : incompatible types in assignment of 'char*' to 'char* [50]'
it copies all the strings in it. So if you output m[0] it'll give you "you" and so on.. but it doesn't pass the strings to the function. Any ideas why?

For starters use code tags when posting code: http://www.cplusplus.com/articles/jEywvCM9/
In your while loops you probably meant to use == (comparison) instead of = (assignment). For that matter, what are those while loops meant to do?

Hi, thank you for your quick response, they copy the content of "str" to buffer. After all elements are copied, the "add" is appended to the end of the resulting buffer. I decrement p such that there is no space in between them.

For example, if I pass m[0] and m[1] (which are basically "you" and "are"), it would return me : youare

When this function is called, it creates the variable a on the stack. Then it grabs the value of a, destroys a, and sends the value to whoever called the function.

1234

int* someFunc() {
int a[20] = {0};
return a;
}

This will create 20 variables in consecutive memory. The address of the first variable is stored in a (a is actually a pointer). When we return, we grab the value of a (the address of the first element), free up all of that memory just like in the first case, then send the address of a to whoever called the function.

The problem is, we just sent the address of memory which has been freed. Nothing exists at that address anymore!

A work-around? (Not a good idea, but this is for the purpose of explanation):

1234

int* someFunc(){
int* a = newint[20];
return a;
}

The new keyword allocates the memory on the heap instead of the stack. The difference is that the memory is not freed automatically when a goes out of scope. It will do exactly what you wanted above. Now here's the problem: this memory will NEVER be freed unless you explicitly delete[] it. It means that you have to start manually managing memory allocation which adds a layer of complexity that is best not to go into. Use "pass by reference" methods as suggested by people above.