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