I have code like this:
unsigned char *buf
*buf=1234567;
How I detect the the size of data buf is pointing to? (In this case is 7)
there is a mistake in your code. buf is a pointer, and you assign it a value
of 1234567.
this means that 1234567 is used as an address, not as data. you should get
compiler warnings for this.
you should use
*buf="1234567";
instead.
this will cause buf to point to a string.
you can then use strlen(buf); to determine the length.
please note that this only gets you the length of the string.
if you have something like this
char mybuf[100];
char* buf = mybuf;
there is no way to get the size of that buffer by just using buf.
there are 2 things you can do:
you have to know in advance how large it will be (for example you have a
BUF_SIZE constant somewhere) or you have to get a size value from somewhere
else when mybuf is assigned to buf.
--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"