strlen [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation
HP C/iX Library Reference Manual
strlen
Computes the length of the string pointed to by s.
Syntax
#include <string.h>
size_t strlen(const char *s);
Parameters
s A pointer to the character string.
Return Values
x The length of the string specified as an unsigned integer.
Description
In the strlen function, s is a character pointer to the null-terminated
string to be scanned. strlen() counts up to, but not including, the
terminating null character. The length of a string containing only a
null character is zero.
NOTE Since the value returned by strlen() is an unsigned number, care
must be taken when performing subtraction operations on the value
returned by the function. The following code fragment is
incorrect:
:
for (i=0;i<=strlen(string)-1;i++
:
The string length of a null string minus one (strlen(string)-1) is
a very large positive number, not minus one (-1) as was intended.
Thus, the code above does not bypass the for loop, but erroneously
executes the loop a large number of times.
Example
len = strlen(string);
The integer len contains the total number of non-null characters in the
string pointed to by string. Thus,
string[len]
is the terminating null in string.
See Also
ANSI C 4.11.6.3, POSIX.1 8.1
MPE/iX 5.0 Documentation