libft/ft_strchr.c

52 lines
1.4 KiB
C

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