You can get the size of all dimensions (3 x 4 x 7) using the sizeof operator.
If you want to know the length of the last one, use strlen in a loop:
#include <stdio.h>
#include <string.h>
int main(void)
{
char data[][4][7] = {{"gsga","baf"},{"ad","aasb","asdf","asdfsd"},{"ads","sd","sd"}};
size_t items1 = sizeof data / sizeof data[0]; /* size of dim 1 */
size_t items2 = sizeof data[0] / sizeof data[0][0]; /* size of dim 2 */
size_t iter1, iter2, count, len;
printf("%zu items\n", items1);
for (iter1 = 0; iter1 < items1; iter1++) {
count = 0;
printf("Item %zu\n", iter1);
for (iter2 = 0; iter2 < items2; iter2++) {
len = strlen(data[iter1][iter2]); /* size of dim 3 */
if (len > 0) {
printf("\tSubitem %zu: %zu characters\n", iter2, len);
count++;
}
}
printf("\t%zu subitems\n", count);
}
return 0;
}
Output:
3 items
Item 0
Subitem 0: 4 characters
Subitem 1: 3 characters
2 subitems
Item 1
Subitem 0: 2 characters
Subitem 1: 4 characters
Subitem 2: 4 characters
Subitem 3: 6 characters
4 subitems
Item 2
Subitem 0: 3 characters
Subitem 1: 2 characters
Subitem 2: 2 characters
3 subitems
data can be also declared as
char *data[][4] = {{"gsga","baf"},{"ad","aasb","asdf","asdfsd"},{"ads","sd","sd"}};
But then you need to check for NULL's to get the number of (non empty) subitems:
for (iter2 = 0; iter2 < items2; iter2++) {
if (data[iter1][iter2] != NULL) {
len = strlen(data[iter1][iter2]);
...
}
}
Full Code
strlen, which requires the strings to be null-terminated. It is not quite clear what you need your arrays for, but you could terminate your other arrays withNULL, too and implement a length function similar tostrlen. (Of course, the terminator would then be a null pointer, not a null char.)