strlen() function in c

C String Length: strlen() function AndroWep

Note that the strlen() function doesn’t count the null character \0 while calculating the length.

#include <stdio.h>
#include <string.h>
int main()
{
    char a[20]="AndroWep";
    char b[20]={'A','n','d','r','o','w','e','p','\0'};
    printf("String a is = %ld \n",strlen(a));
    printf("String b is = %ld \n",strlen(b));
    return 0;
}

Output

String a is = 8
String a is = 8

What is the use of strlen function in C?

C – strlen() functionstrlen( ) function counts the number of characters in a given string and returns the integer value. It stops counting the character when null character is found. Because, null character indicates the end of the string in C.

Does strlen count spaces in C?

strlen() function in cThe strlen() function calculates the length of a given string.The strlen() function is defined in string.h header file. It doesn’t count null character ‘\0’. Syntax: int strlen(const char *str);