|
From: Carlos d. M. <cg...@wo...> - 2002-08-01 10:52:31
|
There is another way for doing things which does not need special
characters.
You need declare two pointers of the kind of the array data, when you
have the last member of the first row you store its direction in the
first pointer, and when you get the last member of the whole array you
store its location in the second pointer. Then you pass to the function
the pointer which defines the array, the first pointer and the second.
Then you declare three ints (of course the first pointer and the first
pointer are optional, see below). And you work with them:
If you want know the size of each row (considering all have the same
size or can be considered as if they have) you substract the array
pointer to the first pointer and sum the size of one element, and store
it in the first int, then you make the same substituting the first
pointer with the second, and store the result in the second int, so now
you have the size of the whole array, and finally you divide the second
int by the first, so you have the number of rows. If you have arrays of
more than two dimensions you need adapt it.
For example:
kind *array, *endrow, *whole;
for(rownum = 0; rownum<number-of.rows-you-need; rownum++){
for(rowmem=0; rowmem<number-of-members-for-each-row; rowmem++){
array[rownum][rowmem];
if(rownum ==0)
endrow = &array[rownum][rowmem];
whole = &array[rownum][rowmem];
}
}
rowsize = endrow - array + sizeof(kind);
wholesize = whole - array + sizeof(kind);
numofrows = wholesize / rowsize;
Of course, if you're interested only in the size of the whole array you
forget rowssize and endrow and if(rownum==0).
|