ft_strchr: initial implementation

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

44
ft_strchr.c Normal file
View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 10:34:23 by kcolin #+# #+# */
/* Updated: 2024/10/16 10:42:16 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
while (s[i] != '\0')
{
if (s[i] == c)
return ((char *)s + i);
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);
}
*/