PC Review


Reply
Thread Tools Rate Thread

Get the length of data a pointer is pointing to

 
 
=?Utf-8?B?VHJhbiBIb25nIFF1YW5n?=
Guest
Posts: n/a
 
      22nd Feb 2006
Hi,

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)

Thanks
Tran Hong Quang
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QnJ1bm8gdmFuIERvb3Jlbg==?=
Guest
Posts: n/a
 
      22nd Feb 2006

> 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.
(E-Mail Removed)
Remove only "_nos_pam"
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Access store its data in fixed length or variable length rows Dennis Microsoft Access Database Table Design 2 15th Jan 2010 05:33 AM
Compaq/Synaptics Pointer-Any way to get pointer to go farther for a given pad motion? frank1492 Windows Vista General Discussion 0 19th Feb 2008 06:46 AM
Pointing to a pointer to an .mdb H. Martins Microsoft Access Form Coding 1 17th Oct 2007 02:48 PM
Example of __gc pointer pointing into the stack Edward Diener Microsoft VC .NET 1 4th Dec 2003 12:43 PM
How to get the fixed length of a fixed length string active Microsoft VB .NET 1 21st Nov 2003 10:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:37 AM.