Originally Posted by
kodax
2. Handle error block in while loop,
- Set variable "err" to TRUE;
- Exit while loop;
Handle error block outside while loop;
- Clean up
3. Array[i] is null before while loop,
therefore it will never be executed.
Note that array[i] changes in while loop.
Also don't deduce anything from a dummy code..
The boolean method is good, much better than an infinite loop.
Judging by how small the function is I question the logic in handling errors outside the loop, just handle it inside and return:
Code:
int catch_error(char *pos);
int foo(char array[]) {
int i = 0, used = 0;
if ( !array )
return -1;
while ( array[i] )
{
used = 1;
if (catch_error(array + i))
{
// Whatever error handling you need here
return -1;
}
// more code
i += used;
}
return i;
}