On this page
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
- Returns
NULLif not found (and matches the terminating'\0'if you search for0).
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
- tuts/c/stdlib/string/strncmp Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strstr 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/string/strtok links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- 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