On this page
strncmp
Prev: strcmp | Up: string.h | Next: strchr
Rel: string.h, stdlib.h & string.h Guide
Ref: cppreference — strncmp
Tags: #public #prog #c #stdlib #string #tier/core
Include
#include <string.h>
Signature & Overview
int strncmp(const char *lhs, const char *rhs, size_t count);
Compares at most count characters of two strings; ideal for prefix checks.
Notes & Pitfalls
- Compares at most
nbytes: Great for prefix checks (strncmp(s, "http://", 7) == 0).
Example
#include <assert.h>
#include <string.h>
int main(void) {
assert(strncmp("https://example.com", "https://", 8) == 0);
}
Linked from
Related notes
- tuts/c/stdlib/string/strchr Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strcmp Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/stdlib_and_string_h Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/string/memchr shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memcmp shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memcpy shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memmove shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memset shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strcat shared tags: #c, #prog, #stdlib, #string, #tier