tags:

views:

225

answers:

4

Hi, if I have an array of pointers like char **lines, how can i determine its length? Thanks

+1  A: 

That's not an array of pointers, it's a pointer to a pointer.

anon
+6  A: 

You can't. You have to manually keep track of the length of arrays.

sth
I'll do. thanks
pistacchio
+3  A: 

You can't reliably.

Sometimes, there is a null pointer marking the end - it is one convention sometimes used. More often, you need to be told the length.

But there is no fool-proof way of determining the length. You have to know (or be told) the length, somehow.

Jonathan Leffler
A: 

It depends on the data. If there is no associated count, it could be a NULL terminated list.

char** lines = mysteryfunction();
for ( ;*lines;lines++ ) { 
    printf( "%s\n", *list ); 
}
Sanjaya R