ft_strncmp.c 1.1 KB

12345678910111213141516171819202122232425
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_strncmp.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2015/11/23 17:03:07 by bchanot #+# #+# */
  9. /* Updated: 2015/12/01 13:33:09 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. int ft_strncmp(const char *s1, const char *s2, size_t n)
  14. {
  15. size_t cpt;
  16. cpt = 0;
  17. while (s1[cpt] == s2[cpt] && s1[cpt] && s2[cpt] && cpt < n)
  18. cpt++;
  19. if (cpt == n)
  20. return (0);
  21. return ((unsigned char)s1[cpt] - (unsigned char)s2[cpt]);
  22. }