I wrote this code:
#include <stdio.h>
void printAllStrings(char **arrPP[])
{
for (char ***p = arrPP; **p != NULL; ++p)
{
int z = 0;
while (*(*p + z) != NULL)
{
printf("%s ", *(*p + z));
z++;
}
putchar('\n');
}
}
void maxLengthString(char **arrPP[])
{
int max = 0;
for (char ***c = arrPP; **c != NULL; ++c)
{
int counter = 0;
int z = 0;
while (*(*c + z) != NULL)
{
counter++;
z++;
if (counter > max)
max = counter;
}
}
printf("%d", max);
}
int main()
{
char *arrP1[] = {"father", "mother", NULL};
char *arrP2[] = {"sister", "brother", "grandfather", NULL};
char *arrP3[] = {"grandmother", NULL};
char *arrP4[] = {"uncle", "aunt", NULL};
char **arrPP[] = {arrP1, arrP2, arrP3, arrP4, NULL};
maxLengthString(arrPP);
printAllStrings(arrPP);
return 0;
}
printAllStrings prints all the arrays that arrPP points at and maxLengthString(char **arrPP[] )should return the longest array. I couldd't return the longest array so I tried to print the max value of length. the output should be:
father mother
sister brother grandfather
grandmother
uncle aunt
3
or
father mother
sister brother grandfather
grandmother
uncle aunt
arrP2 // cause it's the longest array
but nothing is printed why is that?And how could I return the longest array?