Re: [Dev-C++] How to get the number of elements in an array
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2004-01-20 16:28:01
|
And I can't use a for loop and increment the pointer until it reaches the end of the array because that is not safe, according to Code Complete. Any more ideas? Maybe this isn't so easy after all! lol >From: Per Westermark <pw...@ia...> >To: Mohammed Iqbal <mi...@ac...> >CC: Daniel Glenfield <sp...@ho...>, ><dev...@li...> >Subject: Re: [Dev-C++] How to get the number of elements in an array >Date: Tue, 20 Jan 2004 17:21:41 +0100 (CET) > >The idea was good, but it only works for statically allocated arrays. >When the array is dynamically allocated, it isn't possible to check number >of entries. Some low-level functions might return size of the memory block >but that is highly nonportable, and it still doesn't answer number of >array entries, since the allocated block will almost always be rounded up >to a larger size. > >/Per W > >On Tue, 20 Jan 2004, Mohammed Iqbal wrote: > > > n_of_elements=sizeof(Buf)/sizeof(Buf[0]); > > > > Mohammed > > ----- Original Message ----- > > From: "Daniel Glenfield" <sp...@ho...> > > To: <dev...@li...> > > Sent: Tuesday, January 20, 2004 1:49 PM > > Subject: [Dev-C++] How to get the number of elements in an array > > > > > > > This is an easy Q I know but I can't think how to do it... > > > > > > Size = 9; // Decided by a function but set to 9 for this example > > > > > > int* Buf = new int[Size]; > > > > > > int Tmp = sizeof(Buf); > > > > > > This can't be right. How do I get the size? Len(Buf) and Length(Buf) >are > > not > > > recognised (I thought they were functions but I guess not). > > > > > > Any thoughts? > > > > > > _________________________________________________________________ > > > Use MSN Messenger to send music and pics to your friends > > > http://www.msn.co.uk/messenger > > > > > > > > > > > > ------------------------------------------------------- > > > The SF.Net email is sponsored by EclipseCon 2004 > > > Premiere Conference on Open Tools Development and Integration > > > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > > > http://www.eclipsecon.org/osdn > > > _______________________________________________ > > > Dev-cpp-users mailing list > > > Dev...@li... > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > > > > > ------------------------------------------------------- > > The SF.Net email is sponsored by EclipseCon 2004 > > Premiere Conference on Open Tools Development and Integration > > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > > http://www.eclipsecon.org/osdn > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger |