added ft_strnchr & ft_strrnchr

This commit is contained in:
Tanguy MAZE
2018-05-16 12:42:37 +02:00
parent 0ea4e74d77
commit c5a13918c2
4 changed files with 63 additions and 4 deletions

30
ft_strnchr.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}