ft_strrchr.c 1.1 KB

123456789101112131415161718192021222324252627
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strrchr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2015/11/25 13:54:03 by bchanot #+# #+# */
  9. /* Updated: 2018/10/13 22:50:35 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. char *ft_strrchr(const char *s, int c)
  14. {
  15. size_t len;
  16. if (!s || !c)
  17. return (NULL);
  18. len = ft_strlen(s);
  19. while (len && s[len] != (char)c)
  20. len--;
  21. if (s[len] == (char)c)
  22. return ((char *)&s[len]);
  23. return (NULL);
  24. }