diff options
Diffstat (limited to 'c03/ex01/ft_strncmp.c')
| -rw-r--r-- | c03/ex01/ft_strncmp.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/c03/ex01/ft_strncmp.c b/c03/ex01/ft_strncmp.c index 1dc2639..9009164 100644 --- a/c03/ex01/ft_strncmp.c +++ b/c03/ex01/ft_strncmp.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/05 10:50:46 by cacharle #+# #+# */ -/* Updated: 2019/07/05 16:06:57 by cacharle ### ########.fr */ +/* Updated: 2019/07/07 13:58:50 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,12 @@ int ft_strncmp(char *s1, char *s2, unsigned int n) { unsigned int i; + if (n == 0) + return (0); i = 0; - while (s1[i] == s2[i] && s1[i] && s2[i] && i < n - 1) + while (s1[i] == s2[i] && s1[i] && s2[i] && i < n) i++; - return s1[i] - s2[i]; + if (i == n) + i--; + return (s1[i] - s2[i]); } |
