summaryrefslogtreecommitdiffstats
path: root/man/man3/string.3
blob: c7069b6d49de4c6c995a303761411c2e57233c3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.\" References consulted:
.\"     Linux libc source code
.\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
.\"     386BSD man pages
.\" Modified Sun Jul 25 10:54:31 1993, Rik Faith (faith@cs.unc.edu)
.TH string 3 2024-05-02 "Linux man-pages (unreleased)"
.SH NAME
stpcpy, strcasecmp, strcat, strchr, strcmp, strcoll, strcpy, strcspn,
strdup, strfry, strlen, strncat, strncmp, strncpy, strncasecmp, strpbrk,
strrchr, strsep, strspn, strstr, strtok, strxfrm, index, rindex
\- string operations
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.B #include <strings.h>
.TP
.BI "int strcasecmp(const char *" s1 ", const char *" s2 );
Compare the strings
.I s1
and
.I s2
ignoring case.
.TP
.BI "int strncasecmp(const char " s1 [. n "], const char " s2 [. n "], \
size_t " n );
Compare the first
.I n
bytes of the strings
.I s1
and
.I s2
ignoring case.
.TP
.BI "char *index(const char *" s ", int " c );
Identical to
.BR strchr (3).
.TP
.BI "char *rindex(const char *" s ", int " c );
Identical to
.BR strrchr (3).
.TP
.B #include <string.h>
.TP
.BI "char *stpcpy(char *restrict " dest ", const char *restrict " src );
Copy a string from
.I src
to
.IR dest ,
returning a pointer to the end of the resulting string at
.IR dest .
.TP
.BI "char *strcat(char *restrict " dest ", const char *restrict " src );
Append the string
.I src
to the string
.IR dest ,
returning a pointer
.IR dest .
.TP
.BI "char *strchr(const char *" s ", int " c );
Return a pointer to the first occurrence of the character
.I c
in the string
.IR s .
.TP
.BI "int strcmp(const char *" s1 ", const char *" s2 );
Compare the strings
.I s1
with
.IR s2 .
.TP
.BI "int strcoll(const char *" s1 ", const char *" s2 );
Compare the strings
.I s1
with
.I s2
using the current locale.
.TP
.BI "char *strcpy(char *restrict " dest ", const char *restrict " src );
Copy the string
.I src
to
.IR dest ,
returning a pointer to the start of
.IR dest .
.TP
.BI "size_t strcspn(const char *" s ", const char *" reject );
Calculate the length of the initial segment of the string
.I s
which does not contain any of bytes in the string
.IR reject ,
.TP
.BI "char *strdup(const char *" s );
Return a duplicate of the string
.I s
in memory allocated using
.BR malloc (3).
.TP
.BI "char *strfry(char *" string );
Randomly swap the characters in
.IR string .
.TP
.BI "size_t strlen(const char *" s );
Return the length of the string
.IR s .
.TP
.nf
.BI "char *strncat(char " dest "[restrict strlen(." dest ") + ." n " + 1],"
.BI "       const char " src "[restrict ." n ],
.BI "       size_t " n );
.fi
Append at most
.I n
bytes from the unterminated string
.I src
to the string
.IR dest ,
returning a pointer to
.IR dest .
.TP
.BI "int strncmp(const char " s1 [. n "], const char " s2 [. n "], size_t " n );
Compare at most
.I n
bytes of the strings
.I s1
and
.IR s2 .
.TP
.BI "char *strpbrk(const char *" s ", const char *" accept );
Return a pointer to the first occurrence in the string
.I s
of one of the bytes in the string
.IR accept .
.TP
.BI "char *strrchr(const char *" s ", int " c );
Return a pointer to the last occurrence of the character
.I c
in the string
.IR s .
.TP
.BI "char *strsep(char **restrict " stringp ", const char *restrict " delim );
Extract the initial token in
.I stringp
that is delimited by one of the bytes in
.IR delim .
.TP
.BI "size_t strspn(const char *" s ", const char *" accept );
Calculate the length of the starting segment in the string
.I s
that consists entirely of bytes in
.IR accept .
.TP
.BI "char *strstr(const char *" haystack ", const char *" needle );
Find the first occurrence of the substring
.I needle
in the string
.IR haystack ,
returning a pointer to the found substring.
.TP
.BI "char *strtok(char *restrict " s ", const char *restrict " delim );
Extract tokens from the string
.I s
that are delimited by one of the bytes in
.IR delim .
.TP
.nf
.BI "size_t strxfrm(char " dest "[restrict ." n "], \
const char " src "[restrict ." n ],
.BI "        size_t " n );
.fi
Transforms
.I src
to the current locale and copies the first
.I n
bytes to
.IR dest .
.TP
.nf
.BI "char *strncpy(char " dest "[restrict ." n "], \
const char " src "[restrict ." n ],
.BI "       size_t " n );
.fi
Fill a fixed-size buffer with leading non-null bytes from a source array,
padding with null bytes as needed.
.SH DESCRIPTION
The string functions perform operations on null-terminated
strings.
See the individual man pages for descriptions of each function.
.SH SEE ALSO
.BR bstring (3),
.BR stpcpy (3),
.BR strcasecmp (3),
.BR strcat (3),
.BR strchr (3),
.BR strcmp (3),
.BR strcoll (3),
.BR strcpy (3),
.BR strcspn (3),
.BR strdup (3),
.BR strfry (3),
.BR strlen (3),
.BR strncasecmp (3),
.BR strncat (3),
.BR strncmp (3),
.BR strncpy (3),
.BR strpbrk (3),
.BR strrchr (3),
.BR strsep (3),
.BR strspn (3),
.BR strstr (3),
.BR strtok (3),
.BR strxfrm (3)