Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

table length

Status
Not open for further replies.

bbone

Programmer
Joined
Aug 18, 2003
Messages
10
Location
SI
Hi!

I have a problem with computing the length of a table. Let's say, i have a table like this:
double table[] = {..some elements..}
I use sizeof(table)/sizeof(double) and it works fine in main function. But when i use it in some other function, that has table for parameter, it always returns 0.
Why?
Thanks
 
you can only save this size in some variable:
int len;//where will be the size
double *table = new double[len];

by the way, use vectors:
vector<double> x;
double y = sommething;
x.push(y);
x.push(y + 1);
cout<< x.size()<< endl;

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
What returns 0?

Neither sizeof(table) nor sizeof(double) can be 0.
Consequently sizeof(table)/sizeof(double) can't be 0 either.

Instead of implementing your own table, use vector or other collections in STL.


/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top