instead of
logSimpleMessage(&lReceivedData->message, 1);
you put so:
logSimpleMessage(lReceivedData->message, 1);
Question
I have a structure:
typedef struct {
LogLevel level;
char message[255];
} LogMessage;
I then have a function which receives a pointer to a LogMessage structure, and needs to call a function that takes in a char*:
xStatus = xQueueReceive(xQueueHandleGSMSend, &lReceivedData, portMAX_DELAY);
if(xStatus == pdPASS)
{
logSimpleMessage(&lReceivedData->message, 1);
}
Here is the prototype for the logSimpleMessage function:
void logSimpleMessage(const char * message, int level);
When I attempt to call it with the above code, I am not getting the correct address (or contents) of the message. How do I get a char* that points to the message of lReceivedData?
EDIT: I have attempted to use lReceivedData->message, as suggested, but I am still not getting the correct address or values. Here is a screen cap of the IDE... Am I doing something terribly wrong in the debugger, because it seems as though it should work.
Solution
instead of
logSimpleMessage(&lReceivedData->message, 1);
you put so:
logSimpleMessage(lReceivedData->message, 1);
OTHER TIPS
&lReceivedData->message
Produces the address of an array. An array will decay to a pointer when needed, so simply use :
logSimpleMessage(lReceivedData->message, 1);
You cannot truly pass an array to a function, the array will always decay to a pointer to the first element.
You only need to pass lReceivedData->message
to the function, remove the &
:
logSimpleMessage(lReceivedData->message, 1);
A type of char[]
decays to a char*
when passed to a function.