Back to the topic. I have another solution.
The capacity of the array must be known to the function. If the capacity is not hardcoded or saved in a global variable, you need to pass it to the function. Narue proposed to pass it in a second parameter.
Another solution is to make a bundle of the array and its capacity. A cheap, dirty trick is misusing the first array element for it. For strings, the first byte is the string length (lengths from 0 to 255 are possible), for integer array, the first integer is the array length, etc. For non-char or non-integer array, a cast would be neccessary. But this is very dirty and dangerous. Pascal-type strings do this implicitly, which is fine because Pascal hides this trick.
A third solution is to create a struct both of capacity and an array of length 1 (or 0 with gcc).
struct example {
unsigned int len;
char string[1];
}
Allocate dynamically with
malloc(sizeof(struct example) + (len - 1) * sizeof(char)) (not tested). Drop -1 if using string[0].
This works, because C does not check the array bounds. When we say
string[2] , the C compiler won't report errors, and because we allocated memory for it, it will work.