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

strcmp

Prev: strlen | Up: string.h | Next: strncmp
Rel: string.h, stdlib.h & string.h Guide
Ref: cppreference — strcmp
Tags: #public #prog #c #stdlib #string #tier/core


Include

#include <string.h>

Signature & Overview

int strcmp(const char *lhs, const char *rhs);

Lexicographically compares two NUL-terminated strings; returns 0 when identical.

Notes & Pitfalls

Example

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

int main(void) {
    assert(strcmp("alpha", "alpha") == 0);
    assert(strcmp("alpha", "beta") < 0);
}

Linked from

Related notes