Mail Archives: djgpp/1998/02/05/04:01:54
On Thu, 05 Feb 1998 03:59:10 +0800, David Shirley
<shirleyd AT cs DOT curtin DOT edu DOT au> wrote:
>Hi,
>
>Ok heres my problem,
>
>void func(unsigned char *tmp)
>{
>// BLAH BLAH
>}
>
>How do i find how many bytes tmp is taking up in memory:
>
>the sizeof funtion returns 4 bytes, the reason being (i think) that it
>is finding out how many bytes the pointer takes up in memory. I dont
>want to use strlen(tmp) because the string may have a '\0' character.
>
>Can someone tell me how to find out how many bytes tmp takes up in
>memory, OR how to declare it so that sizeof(tmp) will return the correct
>number?
Well, sizeof is right and your statement is right. sizeof() is simply
returning the size of a pointer, which is 4 bytes. The only way to
get the proper size is to include the length of 'tmp'. If you are
putting NULLs in to your string, you will have problems. If it is a
token/marker character, consider changing it to something else.
If the \0 characters *have* to be there, you'll have to figure out the
length yourself, as there is no way the standard c/c++ can.
Cheers,
MooBen
Programmer for some people I can't quite remember
"Winnie says he's *Not* In-Animate"
- Raw text -