-1

I have this variable,

unsigned char identifier1[12];

when I use this identifier is with a cast to

const uint8_t*

like

const uint8_t* getIdentifier() {return identifier1; }

and I receive in a function:

unsigned char *zid

and I want to compare both of them so I use this memcmp(identifier1, zid, 12);

And the answer is 0 so both of them are equal...

but when I print the value:

__android_log_print(ANDROID_LOG_INFO, "MyTag", "%d %d",(int)identifier1,(int)zid);

I get different values in both... like 1711428512 1652772888, but the memcmp gives the write answer... How can I print the values to get the correct value of both of them?

JMR
  • 765
  • 1
  • 8
  • 31

2 Answers2

0

You're printing the pointer value of both arrays, which is different. memcmp() is comparing the contents of those arrays and not the pointers.

Kelmar
  • 165
  • 2
  • 5
0

When you print the array/pointer like that, you're printing the address of the data. If you want to print the data, you can use %s, so long as both are zero terminated.

memcmp doesn't compare the array location to the pointer, it compares the data at the address. So if it returns 0 printing the data at both addresses should result in identical strings.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • but how can I see the real value? imagine to assign to a variable? and print after? – JMR Mar 11 '16 at 13:32