This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.

Released under the GNU General Public License.

Return to index Return to header Previous symbol Next symbol

strlen

Prototype

#include <string.h>

size_t strlen(const char *s);

Description

Returns the number of characters of the specified string s, up to the terminating null character, excluded.

Implementation

View source
#include <string.h>

size_t strlen(const char *s)
{
    const char *p;

    for (p = s; *p != '\0'; ++p)
	;

    return p - s;
}

Example

View source
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
 * len.c: print the length in characters of the argument string.
 * usage: len <string>
 */
int main(int argc, char **argv)
{
    if (argc > 1)
	printf("The length of the argument `%s' is %d\n",
	       argv[1], strlen(argv[1]));

    return EXIT_SUCCESS;
}

References

ISO C 9899:1990 7.11.6.3