typedef struct

26 Jul 2010 . Edited: 26 Jul 2010

I want to print my data from typedef struct, the code is like this:

 

typedef struct _my_data{
int data1
float data2
char data3
}MY_DATA;
MY_DATA data;

#define DATA_SIZE 7

void print_data(){
char *Prnt = (char *)data, i;

data.data1 = 235;
data.data2 = 3.12;
data.data3 = 11;
 
pc.putc(0xFF);
pc.putc(0xFF);
for(i=0;i<DATA_SIZE;i++)  pc.putc(*Prnt++);
pc.putc(0x0D); 
} 

It works on my AVR but in mbed compiler it is error.

 

"No suitable conversion function from "MY_DATA" to "char *" exists (E413)" in file "/Test/print.h"

Can anyone tell me how to overcome this problem???

Thank you,

Agie

26 Jul 2010 . Edited: 26 Jul 2010

Hi Raharja,

The compiler is right on this one! I think what you mean is:

char *Prnt = (char *)&data;

i.e. you are casting the *address* of data to be a char pointer.

Another point: your DATA_SIZE should be 9. An int and float are 4 bytes, and a char is 1 byte. Alternatively you could use the sizeof() operator, so you don't need to work it out manually.

As a general tip, if you post the full code example, it'll be much easier for people to recreate your problem and that'll make it easier to give you answers.

Hope this gets you moving!

Thanks,
Simon