1STRLEN(P) POSIX Programmer's Manual STRLEN(P)
2
3
4
6 strlen - get string length
7
9 #include <string.h>
10
11 size_t strlen(const char *s);
12
13
15 The strlen() function shall compute the number of bytes in the string
16 to which s points, not including the terminating null byte.
17
19 The strlen() function shall return the length of s; no return value
20 shall be reserved to indicate an error.
21
23 No errors are defined.
24
25 The following sections are informative.
26
28 Getting String Lengths
29 The following example sets the maximum length of key and data by using
30 strlen() to get the lengths of those strings.
31
32
33 #include <string.h>
34 ...
35 struct element {
36 char *key;
37 char *data;
38 };
39 ...
40 char *key, *data;
41 int len;
42
43
44 *keylength = *datalength = 0;
45 ...
46 if ((len = strlen(key)) > *keylength)
47 *keylength = len;
48 if ((len = strlen(data)) > *datalength)
49 *datalength = len;
50 ...
51
53 None.
54
56 None.
57
59 None.
60
62 The Base Definitions volume of IEEE Std 1003.1-2001, <string.h>
63
65 Portions of this text are reprinted and reproduced in electronic form
66 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
67 -- Portable Operating System Interface (POSIX), The Open Group Base
68 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
69 Electrical and Electronics Engineers, Inc and The Open Group. In the
70 event of any discrepancy between this version and the original IEEE and
71 The Open Group Standard, the original IEEE and The Open Group Standard
72 is the referee document. The original Standard can be obtained online
73 at http://www.opengroup.org/unix/online.html .
74
75
76
77IEEE/The Open Group 2003 STRLEN(P)