-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strncmp.c
More file actions
39 lines (35 loc) · 1.39 KB
/
ft_strncmp.c
File metadata and controls
39 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strncmp.c :+: :+: */
/* +:+ */
/* By: farodrig <farodrig@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/27 11:18:35 by farodrig #+# #+# */
/* Updated: 2020/12/04 19:28:23 by farodrig ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Compares not more than n character. Returns an integer greater than,
** equal to, or less than 0, according as the string str1 is greater than,
** equal to, or less than the string str2.
*/
int ft_strncmp(char *str1, char *str2, size_t len)
{
unsigned char *ptr1;
unsigned char *ptr2;
size_t i;
ptr1 = (unsigned char*)str1;
ptr2 = (unsigned char*)str2;
i = 0;
while ((ptr1[i] || ptr2[i]) && i < len)
{
if (ptr1[i] != ptr2[i])
{
return (ptr1[i] - ptr2[i]);
}
i++;
}
return (0);
}