fix(ft_strrchr): c was not cast to char for check agains \0

This commit is contained in:
Khaïs COLIN 2024-10-23 10:38:03 +02:00
parent 6236107bd4
commit d068a9444b

View file

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