Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_strncmp.c File Reference
#include <stdlib.h>
+ Include dependency graph for ft_strncmp.c:

Go to the source code of this file.

Functions

int ft_strncmp (const char *s1, const char *s2, size_t n)
 Compares two strings up to a maximum number of characters.
 

Function Documentation

◆ ft_strncmp()

int ft_strncmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Compares two strings up to a maximum number of characters.

Parameters
s1First string.
s2Second string.
nMaximum number of characters to compare.
Returns
Negative, zero, or positive difference at first mismatch.

Definition at line 23 of file ft_strncmp.c.

24{
25 size_t i;
26
27 i = 0;
28 if (n == 0)
29 return (0);
30 while (s1[i] && s2[i] && s1[i] == s2[i] && i < n - 1)
31 i++;
32 return ((unsigned char)s1[i] - (unsigned char)s2[i]);
33}