On this page
  1. strncmp
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

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

Example

#include <assert.h>
#include <string.h>

int main(void) {
    assert(strncmp("https://example.com", "https://", 8) == 0);
}

Linked from

Related notes