w3resource

C - strlen()

C strlen() function - Get length of fixed size string

The strlen() function is used to get the length of a string excluding the ending null character.

Syntax:

size_t strlen(const char *str)

Parameters:

Name Description Required /Optional
str Null-terminated string. Required

Return value from strlen()

  • The strlen() function returns the length of str.
  • No return value shall be reserved to indicate an error.

Example: strlen() function


#include<stdio.h>
#include<string.h>
int main()
{
    char name[20]="w3resource.com";
    int length;
    length = strlen(name);
    printf("Length of %s = %d\n",name,length);
    return 0;
}

Output:

Length of w3resource.com = 14

C Programming Code Editor:

Previous C Programming: C strerror()
Next C Programming: C strpbrk()



Follow us on Facebook and Twitter for latest update.