I've been searching for hours how to find a way to pass strings to a function in C but they all seem to need either the length of the array or very specific information. I'm trying to make a function that will list a given array of strings so can vary in lengths in either dimension.
Currently I have:
void printStrings(char *arr[])
{
for (int i = 0; i < 2; i++)
{ //print all list items
printf(" %s\n", arr[i]);
}
}
int main(int argc, char *argv[])
{
char *list[2] = {"Hello", "Goodbye"};
printStrings(list);
return 0;
}
I want to be able to read the length of the array in printStrings to eliminate the hard coded 2 in the for loop so that it can run for all lengths.
This is not the same as asking the length of an array directly as it involves passing the array to a function.