diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-07 15:29:30 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-07 15:29:30 +0200 |
| commit | a2ef228b981df5ad417a0e8377e1e832002a7644 (patch) | |
| tree | 32827b5be808bf3123d46856bb753fc190fd3611 /c03/ex01 | |
| parent | 79f8ba0b777f3361002ed2ae0c6c6f8f353ca731 (diff) | |
| download | piscine-a2ef228b981df5ad417a0e8377e1e832002a7644.tar.gz piscine-a2ef228b981df5ad417a0e8377e1e832002a7644.tar.bz2 piscine-a2ef228b981df5ad417a0e8377e1e832002a7644.zip | |
c04/c05 testing + c06
Diffstat (limited to 'c03/ex01')
| -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]); } |
