Debian Codegraph @

upstream/mageia-cauldron/man3/strchr.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH strchr 3 2026-02-08 "Linux man-pages 6.17"
8 .SH NAME
9 strchr, strrchr, strchrnul \- locate character in string
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <string.h>
16 .P
17 .BI "char *strchr(const char *" s ", int " c );
18 .BI "char *strrchr(const char *" s ", int " c );
19 .P
20 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
21 .B #include <string.h>
22 .P
23 .BI "char *strchrnul(const char *" s ", int " c );
24 .fi
25 .SH DESCRIPTION
26 The
27 .BR strchr ()
28 function returns a pointer to the first occurrence
29 of the character
30 .I c
31 in the string
32 .IR s .
33 .P
34 The
35 .BR strrchr ()
36 function returns a pointer to the last occurrence
37 of the character
38 .I c
39 in the string
40 .IR s .
41 .P
42 The
43 .BR strchrnul ()
44 function is like
45 .BR strchr ()
46 except that if
47 .I c
48 is not found in
49 .IR s ,
50 then it returns a pointer to the null byte
51 at the end of
52 .IR s ,
53 rather than NULL.
54 .P
55 Here "character" means "byte";
56 these functions do not work with
57 wide or multibyte characters.
58 .SH RETURN VALUE
59 The
60 .BR strchr ()
61 and
62 .BR strrchr ()
63 functions return a pointer to
64 the matched character or NULL if the character is not found.
65 The terminating null byte is considered part of the string,
66 so that if
67 .I c
68 is specified as \[aq]\[rs]0\[aq],
69 these functions return a pointer to the terminator.
70 .P
71 The
72 .BR strchrnul ()
73 function returns a pointer to the matched character,
74 or a pointer to the null byte at the end of
75 .I s
76 (i.e.,
77 .IR "s+strlen(s)" )
78 if the character is not found.
79 .SH ATTRIBUTES
80 For an explanation of the terms used in this section, see
81 .BR attributes (7).
82 .TS
83 allbox;
84 lbx lb lb
85 l l l.
86 Interface Attribute Value
87 T{
88 .na
89 .nh
90 .BR strchr (),
91 .BR strrchr (),
92 .BR strchrnul ()
93 T} Thread safety MT-Safe
94 .TE
95 .SH STANDARDS
96 .TP
97 .BR strchr ()
98 .TQ
99 .BR strrchr ()
100 C11, POSIX.1-2008.
101 .TP
102 .BR strchrnul ()
103 GNU.
104 .SH HISTORY
105 .TP
106 .BR strchr ()
107 .TQ
108 .BR strrchr ()
109 POSIX.1-2001, C89, SVr4, 4.3BSD.
110 .TP
111 .BR strchrnul ()
112 glibc 2.1.1,
113 FreeBSD 10,
114 NetBSD 8.
115 .SH SEE ALSO
116 .BR memchr (3),
117 .BR string (3),
118 .BR strlen (3),
119 .BR strpbrk (3),
120 .BR strsep (3),
121 .BR strspn (3),
122 .BR strstr (3),
123 .BR strtok (3),
124 .BR wcschr (3),
125 .BR wcsrchr (3)