I have this function:
int setIncludes(char *includes[]);
I don’t know how many values includes will take. It may take includes[5], it may take includes[500]. So what function could I use to get the length of includes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is none. That’s because arrays will decay to a pointer to the first element when passing to a function.
You have to either pass the length yourself or use something in the array itself to indicate the size.
First, the “pass the length” option. Call your function with something like:
A sentinel method uses a special value at the end to indicate no more elements (similar to the
\0at the end of a Cchararray to indicate a string) and would be something like this:Another method I’ve seen used (mostly for integral arrays) is to use the first item as a length (similar to Rexx stem variables):