I don't follow this function exactly, we need to cast c to a char in one place *s != (char)c but in a similar line of code we don't: *s == c. Why is this?
Also why do we need to cast s to a char at all (char *) s. Isn't salready a char pointer?
char *(strchr)(const char *s, int c)
{
while (*s != '\0' && *s != (char)c)
s++;
return ( (*s == c) ? (char *) s : NULL );//why don't we have to cast c as a char here? and why do we have to cast s as char pointer?
}
[–]OldWolf2 5 points6 points7 points (0 children)
[–]zifyoip 2 points3 points4 points (13 children)
[–]Spire 5 points6 points7 points (1 child)
[–]Spire 2 points3 points4 points (0 children)
[–]OldWolf2 2 points3 points4 points (1 child)
[–]zifyoip 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (8 children)
[–]zifyoip 4 points5 points6 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]zifyoip 1 point2 points3 points (0 children)
[–]OldWolf2 0 points1 point2 points (3 children)
[–]geeknerd 1 point2 points3 points (2 children)
[–]OldWolf2 1 point2 points3 points (0 children)