JoJI JoJI - 1 year ago 78
C Question

How to assign the integer to pointer data?

I'm not familiar with C language. I'm studying it.

I've got a function as looks like this.
I'm keep trying to do to assign integer data to uint8_t *data but it does not.
I've got a error 0x00 does not match to uint8_t *data.
how do I assign to my integer(0x00) data to there?

sccb_write_reg(0x01, 0x00); //<---it makes error

void sccb_write_reg(uint16_t reg, uint8_t *data)

Would you please let me know how to solve this problem?

Answer Source

For this particular case, the context clues tell us there should be data in the calling function and you should pass its address in:

uint8_t data = 0x00;
uin16_t reg = 0x01;
sccb_write_reg(reg, &data);

Note the ampersand (&) before the data. That says, "Pass in the address of data" which is what a uint8_t * is, it's a memory address.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download