This commit is contained in:
K. Lange 2018-05-04 12:21:52 +09:00
parent f94a09f485
commit 5a737917b0
2 changed files with 14 additions and 0 deletions

View File

@ -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
View 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;
}