C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-02-2003, 11:53 PM   #1
Registered User
 
Join Date: Jul 2003
Posts: 32
Is there a way to find the number of elements in an array?

Here's a simple question that I don't know the answer to. I hope someone knows a trick or two.

Say you have two arrays and you want to make a single function to print the out the elements. One is size 2 and one is size 3 let's say. Is there a way to read the number of elements in an array so that you don't print out 3 elements if you're printing the array with 2 elements?
lime is offline   Reply With Quote
Old 08-03-2003, 02:04 AM   #2
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,643
Or you could always do something odd like use the first element of the array to hold the total number of elements in the array.
Code:
char array[100] = {100};
Why you'd want to do this is beyond me, but you could.

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 08-03-2003, 10:01 AM   #3
Registered User
 
Join Date: Jul 2003
Posts: 32
would NELEM(x) also work for arrays of pointers?
lime is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
xor linked list adramalech C Programming 23 10-14-2008 10:13 AM
using realloc for a dynamically growing array broli86 C Programming 10 06-27-2008 05:37 AM
Template Array Class hpy_gilmore8 C++ Programming 15 04-11-2004 11:15 PM
Struct *** initialization Saravanan C Programming 20 10-09-2003 12:04 PM
Can't find the lowest number in array? Nate2430 C++ Programming 1 11-20-2001 10:21 AM


All times are GMT -6. The time now is 09:23 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22