I have a short example of a C library that I have coded below along with the header. I am calling this function from a C++ client app.
Some of the warning I get are as follows. This normally gives me a segmentation stack run time error. So I guess some about memory not been allocated being assigned to null address.
warning: return from incompatible pointer type
warning: function returns address of local variable
I have tried many different ways to do this. As you can see from my commenting out pieces of code.
However, I can return pointer without any problems. However, my code needs to return a string array. i.e. char msgTest = "Hello how are you";
Can any one offer any advice on this?
Many thanks for any suggestions.
And the C++ code for calling the above function.
//C library code
char* returnMessage(char *message);
char* returnMessage(char *message)
printf("Message: %s\n", message);
char *msg = NULL;
// //msg = message;
// printf("msg = message: %s\n", msg);
// //strcpy(msg, message);
// printf("strcpy(msg, message): %s\n", msg);
char msgTest = "Hello how are you";
int main(int argc, char** argv)
char *ptrTest = NULL;
char test = "Hello";
ptrTest = test;
char *ptrRtn = NULL;
ptrRtn = returnMessage(ptrTest);
cout << "PtrRtn: " << ptrRtn << endl;