strchr.c 528 B

12345678910111213141516171819202122232425262728
  1. /* Portable version of strchr()
  2. This function is in the public domain. */
  3. /*
  4. @deftypefn Supplemental char* strchr (const char *@var{s}, int @var{c})
  5. Returns a pointer to the first occurrence of the character @var{c} in
  6. the string @var{s}, or @code{NULL} if not found. If @var{c} is itself the
  7. null character, the results are undefined.
  8. @end deftypefn
  9. */
  10. #include <ansidecl.h>
  11. char *
  12. strchr (register const char *s, int c)
  13. {
  14. do {
  15. if (*s == c)
  16. {
  17. return (char*)s;
  18. }
  19. } while (*s++);
  20. return (0);
  21. }