strncmp
This commit is contained in:
parent
f94a09f485
commit
5a737917b0
@ -25,6 +25,7 @@ extern char * strpbrk(const char * s, const char * b);
|
||||
extern char * strstr(const char * h, const char * n);
|
||||
|
||||
extern int strcmp(const char * l, const char * r);
|
||||
extern int strncmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
extern size_t strcspn(const char * s, const char * c);
|
||||
extern size_t strspn(const char * s, const char * c);
|
||||
|
13
libc/string/strncmp.c
Normal file
13
libc/string/strncmp.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <string.h>
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||
size_t i = 0;
|
||||
while (i < n && *s1 && *s2) {
|
||||
if (*s1 < *s2) return -1;
|
||||
if (*s1 > *s2) return 1;
|
||||
s1++;
|
||||
s2++;
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user