|
-
Dec 8th, 2002, 06:13 PM
#1
Thread Starter
Frenzied Member
Length of Array in C
Hey guys, I really need ur help on this one!
How do I find out the length of an array using C?
for instance...
I have an array that has 10 values in it, how do I get this number programatically...
thanx in advance,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Dec 9th, 2002, 04:19 AM
#2
Monday Morning Lunatic
You can't, really.
Unless you specifically have a 10 item array:
Code:
void somecode() {
int blah[10];
}
...in which case you can use (sizeof(blah) / sizeof(int)) to get the number of items. If you've used malloc to obtain a pointer to a memory location, then there's no way, and you need to keep track of the size yourself.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 9th, 2002, 08:12 AM
#3
And if you have int blah[10] then there's no reason to compute the size. Note also that this only works in the function you declared the array.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|