From: bena AT NOSPAMsirplc DOT co DOT uk (Ben Ashley) Newsgroups: comp.os.msdos.djgpp Subject: Re: Sizeof and pointers Date: Thu, 05 Feb 1998 08:36:14 GMT Organization: UUNet UK server (post doesn't reflect views of UUNet UK) Lines: 41 Message-ID: <34d97979.720731@suckfeed.news.pipex.net> References: <34D8C88E DOT 2849A0A AT cs DOT curtin DOT edu DOT au> Reply-To: bena AT sirplcNOSPAM DOT co DOT uk NNTP-Posting-Host: tigger.sirplc.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Thu, 05 Feb 1998 03:59:10 +0800, David Shirley 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"