ft_strrchr: intial implementation

This commit is contained in:
Khaïs COLIN 2024-10-16 10:52:03 +02:00
parent 3754c47e8c
commit 10cf338cbf
3 changed files with 50 additions and 2 deletions

View file

@ -6,7 +6,7 @@
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ # # By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# # # Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
# Updated: 2024/10/16 10:46:03 by kcolin ### ########.fr # # Updated: 2024/10/16 10:46:46 by kcolin ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -26,7 +26,8 @@ SOURCES = ft_isalpha.c \
ft_strlcat.c \ ft_strlcat.c \
ft_toupper.c \ ft_toupper.c \
ft_tolower.c \ ft_tolower.c \
ft_strchr.c ft_strchr.c \
ft_strrchr.c
OBJECTS = $(SOURCES:.c=.o) OBJECTS = $(SOURCES:.c=.o)
CC = gcc CC = gcc

46
ft_strrchr.c Normal file
View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 10:34:23 by kcolin #+# #+# */
/* Updated: 2024/10/16 10:48:57 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
i = ft_strlen(s);
while (i != 0)
{
i--;
if (s[i] == c)
return ((char *)s + i);
}
return (0);
}
/*
#include <stdio.h>
int main(int argc, char **argv)
{
char *result;
if (argc > 2)
{
result = ft_strrchr(argv[1], argv[2][0]);
if (result == 0)
printf("(null)\n");
else
printf("%s\n", result);
}
return (0);
}
*/

View file

@ -34,5 +34,6 @@ int ft_toupper(int c);
int ft_tolower(int c); int ft_tolower(int c);
char *ft_strchr(const char *s, int c); char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
#endif #endif