libft/ft_strrchr.c

55 lines
1.5 KiB
C
Raw Permalink Normal View History

2024-10-16 10:52:03 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 10:34:23 by kcolin #+# #+# */
/* Updated: 2024/10/23 10:37:05 by kcolin ### ########.fr */
2024-10-16 10:52:03 +02:00
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
i = ft_strlen(s);
if ((char)c == '\0')
return ((char *)s + i);
2024-10-16 10:52:03 +02:00
while (i != 0)
{
i--;
if (s[i] == (unsigned char)c)
2024-10-16 10:52:03 +02:00
return ((char *)s + i);
}
return (0);
}
/*
#include <stdio.h> // bad
#include <string.h> // bad
2024-10-16 10:52:03 +02:00
int main(int argc, char **argv)
{
char *result;
if (argc > 1)
2024-10-16 10:52:03 +02:00
{
result = ft_strrchr(argv[1], '\0' + 256);
2024-10-16 10:52:03 +02:00
if (result == 0)
printf("(null)\n");
else
printf("[%p]\n", result);
result = strrchr(argv[1], '\0' + 256);
if (result == 0)
printf("(null)\n");
else
printf("[%p]\n", result);
2024-10-16 10:52:03 +02:00
}
return (0);
}
*/