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