I found this implementation for char * strchr (const char *string, int c);
:
for (;;)
if (*string == c)
return (char *) string;
else if (*string == '\0')
return NULL;
else
string++;
For me, though, it would be equivalent to do the following, which would be way easier to read:
while (*string != c && *string != '\0')
string++;
return (*string == c) ? ((char *) string) : (NULL);
I take it there is some reason for the libc to implement the first one. But any take on what's the reason behind it?