Monday, 15 March 2010

Finding the length of an array in C -



Finding the length of an array in C -

i'm trying find length of array of "header" structures defined (a header holds few informational int members, if relevant here). effort passing fl, pointer start of array, , idx, index value indicates proper fl_tails pointer is stationed @ end of array (in other/repetitive words, 'fl_tails[idx]` pointer end):

int arr_size(header* fl, int idx){ int cnt = 1; /* passed guaranteed have @ to the lowest degree 1 */ while(fl != fl_tails[idx]){ fl++; cnt++; } }

i thought advance fl pointer , generate count until end reached, goes infinite loop. i'm wondering if caused in function or elsewhere need find. when printed addresses of origin , end unsigned ints, seemed innocuous enough---things 16777216 , 16777344, respectively. maybe wrong understanding of header construction , size/effect on steps?

you want compare addresses, so:

while(fl != &fl_tails[idx]) ^

c arrays pointers

No comments:

Post a Comment