I am trying to assign a string to a pointer which is in the structure. Even though, I am able to initialise the string to pointer successfully, when I try to use the string(access the pointer), I get some random values. How should I solve the problem. Following is my code:
typedef struct
{
uint8_t LOG_ID;
uint8_t timestamp;
uint8_t loglength;
uint8_t checksum;
uint8_t *payload;
} Log;
Log LB_t;
void main(){
LB_t.LOG_ID=1;
LB_t.timestamp=3;
LB_t.loglength=17;
LB_t.checksum=89;
LB_t.payload="LED initialised";
log_item(&LB_t,17);
}
void log_item(uint8_t *logptr,uint8_t length){
while(length!=0){
CB_buffer_add_item(tx,*logptr);
length=length-1;
logptr++;
}
}
Is there any alternate way in which I can access the pointer?
main()returnsint.uint8_tis not guaranteed to exist, nor to be compatible withchar(i.e. a "string"). Please format your code properly if you expect others to read it. And please provide examples of input and output data.payloadnotchar*. Why islog_itemarg not of typeLog? What is CB_buffer_add_itemvoid main()is OK.offsetof(). Is that right? It usually doesn't end well for people who try it.17?