table of contents
| strchr(3) | Library Functions Manual | strchr(3) |
NAME¶
strchr, strrchr - locate character in string
LIBRARY¶
Standard C library (libc, -lc)
SYNOPSIS¶
#include <string.h>
char *strchr(const char *s, int c); char *strrchr(const char *s, int c);
DESCRIPTION¶
- strchr()
- The strchr() function returns a pointer to the first occurrence of the character c in the string s.
- It is equivalent to both of the following expressions:
-
memchr(s, c, strlen(s) + 1) strpbrk(s, (char [2]){c, '\0'})
- strrchr()
- The strrchr() function returns a pointer to the last occurrence of the character c in the string s.
- It is equivalent to
-
memrchr(s, c, strlen(s) + 1)
RETURN VALUE¶
The strchr() and strrchr() functions return a pointer to the matched character or NULL if the character is not found. The terminating null byte is considered part of the string, so that if c is specified as '\0', these functions return a pointer to the terminator.
ATTRIBUTES¶
For an explanation of the terms used in this section, see attributes(7).
| Interface | Attribute | Value |
| strchr (), strrchr () | Thread safety | MT-Safe |
STANDARDS¶
C11, POSIX.1-2008.
HISTORY¶
POSIX.1-2001, C89, SVr4, 4.3BSD.
SEE ALSO¶
memchr(3), string(3), strchrnul(3), strlen(3), strnul(3), strpbrk(3), strsep(3), strspn(3), strstr(3), strtok(3), wcschr(3), wcsrchr(3)
| 2026-02-25 | Linux man-pages 6.18 |