if I have an array of pointers like char **lines, how can i determine its length? Thanks
如果我有一个指针数组,比如char **lines,我如何确定它的长度?谢谢
5 个解决方案
#1
7
You can't. You have to manually keep track of the length of arrays.
你不能。您必须手动跟踪数组的长度。
#2
4
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.
但是没有万无一失的方法来确定长度。你必须知道(或被告知)长度。
#3
1
That's not an array of pointers, it's a pointer to a pointer.
它不是指针数组,而是指向指针的指针。
#4
1
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 );
}
#5
-1
Getting the length of a pointer to an array
char *array[]={"welcome","to","India"};
length=sizeof(array)/sizeof(array[0]);
Output:
输出:
3
3
we can get the length by dividing (size of pointer to array by size of single one)
我们可以通过划分(大小为单个的数组的指针大小)来获得长度
Because there is no predefined function for getting length of array..
因为没有预定义的函数来获取数组的长度。
#1
7
You can't. You have to manually keep track of the length of arrays.
你不能。您必须手动跟踪数组的长度。
#2
4
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.
但是没有万无一失的方法来确定长度。你必须知道(或被告知)长度。
#3
1
That's not an array of pointers, it's a pointer to a pointer.
它不是指针数组,而是指向指针的指针。
#4
1
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 );
}
#5
-1
Getting the length of a pointer to an array
char *array[]={"welcome","to","India"};
length=sizeof(array)/sizeof(array[0]);
Output:
输出:
3
3
we can get the length by dividing (size of pointer to array by size of single one)
我们可以通过划分(大小为单个的数组的指针大小)来获得长度
Because there is no predefined function for getting length of array..
因为没有预定义的函数来获取数组的长度。