mirror of
https://github.com/gbdk-2020/gbdk-2020.git
synced 2026-03-15 03:38:02 +01:00
17 lines
299 B
C
17 lines
299 B
C
#include <string.h>
|
|
|
|
/*
|
|
* Compare strings (at most n bytes):
|
|
* s1>s2: >0
|
|
* s1==s2: 0
|
|
* s1<s2: <0
|
|
*/
|
|
|
|
int strncmp(const char *s1, const char *s2, int n) {
|
|
while ((n > 0) && (*s1 == *s2++)) {
|
|
if (*s1++ == '\0') return 0;
|
|
n--;
|
|
}
|
|
return (n == 0 ? 0 : *s1 - *--s2);
|
|
}
|