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

strchr

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


Include

#include <string.h>

Signature & Overview

char *strchr(const char *str, int ch);

Returns pointer to the first occurrence of (char)ch in str (or NULL). Use strrchr for the last occurrence.

Notes & Pitfalls

Example

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

int main(void) {
    const char *p = strchr("a:b:c", ':');
    assert(p != NULL && strcmp(p, ":b:c") == 0);
}

Linked from

Related notes