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
>
|