I got a char **function which returns obviously an Array of chars…. the problem is that I don’t know how many strings are filled in the array …. char *data[size_of_data]; has been set at the first, but the function may not need all the array fields….
presume I got int size_of_data = 100 , but it just got 15 Strings …. if I want to break after the 15th String, which condition do I need in C … I got the data already in a char ** field and tried sth like….
while(strcmp(data[i],'\0'))
{
msg_send (session, para[0],data[i]);
printf("------> %s \n",data[i]);
}
One thing you can do is to also provide the size of the array as an out parameter. Your function signature would look like this
Then you do something like so
There’s an advantage to knowing the size, instead of just iterating until you hit a null pointer. Say you prepared an array of 100
char*. What if you use them all? There’s no null pointer, and you’ll have overrun your buffer. Of course, you could add an extra pointer at the end as a delimiter, but personally I like having the size.