libft/ft_strchr.c
Khaïs COLIN d517a05f90 ft_strchr: fix 2 small bugs
1. Compairing was done with ints, not bytes
2. did not correctly give pointer to null terminator
2024-10-18 17:44:41 +02:00

46 lines
1.3 KiB
C

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