strlen()

The strlen() string function returns the length of the string without including terminating character '\n'.

Syntax

strlen(string)

It takes in the string and returns an unsigned short.

Example

#include <stdio.h>
#include <string.h>
int main() {
char spell[20] = "Abracadabra";
printf("Length: %i", strlen(spell));
return 0;
}

The output would be:

Length: 11

Notice how it didn’t count the terminating character.

Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn C on Codecademy

Edit this page on GitHub

Contributors