Seluj78/Minishell

View on GitHub
libft/ft_strncmp.c

Summary

Maintainability
Test Coverage
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_strncmp.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: jlasne <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2016/11/03 14:14:54 by jlasne            #+#    #+#             */
/*   Updated: 2016/11/03 14:15:04 by jlasne           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"

int        ft_strncmp(const char *s1, const char *s2, size_t n)
{
    size_t            i;
    unsigned char    *c_s1;
    unsigned char    *c_s2;

    i = 0;
    c_s1 = (unsigned char *)s1;
    c_s2 = (unsigned char *)s2;
    while (c_s1[i] != '\0' && c_s2[i] != '\0' && c_s1[i] == c_s2[i] && i < n)
        i++;
    if (i == n)
        return (0);
    return (c_s1[i] - c_s2[i]);
}