AW> Just wondering, if an array is passed to a function, is there a way
AW> to test for or find the end of the array without having the size of
AW> the array passed to the function?
AW> If it's a char string one could search/test for the null character,
AW> but what if it's an array of integers?
In a string, we have decided (I use the term "we" loosely since neither you
nor I decided this) to use the nul as a terminator. We have decided that nul
won't appear anywhere in a useful string, so it can be used as the
termination character.
If, however, you have binary data - where the nul character could exist -
there is no way to determine the end of data since all data is "valid".
Your array of integers is the same way. If it is a "string" of integers (you
have a terminating value), you can detect that terminator. Otherwise you
cannot determine the end. For example, a string of integers:
#define END_OF_INT_STRING -999
int array[] = {
0, 15, 39, -35, -2512, 539, 95, -53, END_OF_INT_STRING
};
(Usually in a case like this, we would use INT_MIN or INT_MAX for the end of
string value, but if we need to use that value, we can create our own
terminator value that we know is not used anywhere else.)
Good luck,
--- Maximus/2 3.01
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|