Chapter Contents |
Previous |
Next |
strlen |
Portability: | ISO/ANSI C conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTION | |
PORTABILITY | |
IMPLEMENTATION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <string.h> size_t strlen(const char *str);
DESCRIPTION |
strlen
returns the length of a null-terminated character string
str
.
RETURN VALUE |
The return value is the length of the string, not counting the terminating null.
CAUTION |
PORTABILITY |
Note that many implementations before
ANSI C define
strlen
to return
int
rather than
size_t
.
IMPLEMENTATION |
If
<string.h>
is included (by an
#include
statement)
and
strlen
is not undefined (by an
#undef
statement),
strlen
generates inline code. If the argument to
strlen
is a constant, the length is evaluated during compilation, and
no code is generated for the function.
EXAMPLE |
#include <string.h> #include <stdio.h> #define MAXLINE 100 main() { char line[MAXLINE+1]; puts("Enter some text (at least 2 characters):"); gets(line); puts("The last half of your text is:"); puts(line + (strlen(line)/2)); }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.