fix(ft_strchr): c was not cast to char for check agains \0
This commit is contained in:
parent
88a147fd0f
commit
6236107bd4
1 changed files with 13 additions and 7 deletions
20
ft_strchr.c
20
ft_strchr.c
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/16 10:34:23 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/18 17:42:51 by kcolin ### ########.fr */
|
||||
/* Updated: 2024/10/23 10:33:55 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,29 +17,35 @@ char *ft_strchr(const char *s, int c)
|
|||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
if (s[i] == (unsigned char)c)
|
||||
if (s[i] == (char)c)
|
||||
return ((char *)s + i);
|
||||
i++;
|
||||
}
|
||||
if (c == '\0')
|
||||
if ((char)c == '\0')
|
||||
return ((char *)s + i);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
#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_strchr(argv[1], argv[2][0]);
|
||||
result = ft_strchr(argv[1], '\0' + 256);
|
||||
if (result == 0)
|
||||
printf("(null)\n");
|
||||
else
|
||||
printf("%s\n", result);
|
||||
printf("[%p]\n", result);
|
||||
result = strchr(argv[1], '\0' + 256);
|
||||
if (result == 0)
|
||||
printf("(null)\n");
|
||||
else
|
||||
printf("[%p]\n", result);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue