Go to the first, previous, next, last section, table of contents.


String Length

You can get the length of a string using the strlen function. This function is declared in the header file `string.h'.

Function: size_t strlen (const char *s)
The strlen function returns the length of the null-terminated string s. (In other words, it returns the offset of the terminating null character within the array.)

For example,

strlen ("hello, world")
    => 12

When applied to a character array, the strlen function returns the length of the string stored there, not its allocation size. You can get the allocation size of the character array that holds a string using the sizeof operator:

char string[32] = "hello, world";
sizeof (string)
    => 32
strlen (string)
    => 12


Go to the first, previous, next, last section, table of contents.