libft/ft_strnchr.c
2018-05-16 12:42:37 +02:00

31 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/16 11:41:02 by tmaze #+# #+# */
/* Updated: 2018/05/16 11:56:15 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include "libft.h"
char *ft_strnchr(const char *s, int c, int n)
{
int i;
char *tmp;
i = -1;
tmp = (char*)s;
while ((++i == 0 || tmp[i - 1]) && n > 0 && i < n)
{
printf("loop %d\nc: %c\ntmp[i]: %c\n", i, c, tmp[i]);
if (tmp[i] == c)
return (&tmp[i]);
}
return (NULL);
}