Implement the strchr function as efficiently as you can.. How do you handle errors if you had to
char * strrchr (const char * s, int c) { size_t len = strlen (s); while (len > 0) { --len; if (s[len] == c) { return (char *)(s + len); } } return NULL; }
[code:1]char* str_chr(char* str, char c) { char* t = str; while(*t != c && *t) t++;
return *--t ? NULL : t; }[/code:1]
strchr from pnets libc code
char *
strrchr (const char * s, int c)
{
size_t len = strlen (s);
while (len > 0)
{
--len;
if (s[len] == c)
{
return (char *)(s + len);
}
}
return NULL;
}
Implement the strchr function
[code:1]char* str_chr(char* str, char c)
{
char* t = str;
while(*t != c && *t)
t++;
return *--t ? NULL : t;
}[/code:1]