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