C Programming Language


#include < string.h>
size_t strlen( char *str );

strlen(char *str) returns the length of the null terminated string pointed to by str. The null terminator is not counted.

This function will return number of characters in the string provided as parameter to this function. For example if we are providing "The world" as the string it will return 9. That means it will take the blank spaces in between the words in the string into count. But the null terminator is not counted. It will aslo take special characters like @,#,$,% etc into count.

consider this example str[30]="www.cprogrammingexpert.com";

It is stored like

str[0]  <- 'w'
str[1]  <- 'w'
str[2]  <- 'w'
str[3]  <- '.'
str[4]  <- 'c'
str[5]  <- 'p'
str[6]  <- 'r'
str[7]  <- 'o'
str[8]  <- 'g'
str[9]  <- 'r'
str[10]   <-'a'                   
str[11]   <-'m'   
str[12]   <-'m'   
str[13]   <-'i'   
str[14]   <-'n'   
str[15]   <-'g'   
str[16]   <- 'e' 
str[17]   <- 'x'
str[18]   <- 'p'
str[19]   <- 'e'
str[20]   <- 'r'
str[21]   <- 't'
str[22]   <- '.'
str[23]   <- 'c'
str[24]   <- 'o'
str[25]   <- 'm'
str[26]   <- '\0'
str[27]   <- 'garbage value'
str[28]   <- 'garbage value'
str[29]   <- 'garbage value'

Here strlen(str) equals 26. null terminator is not counted.


String Home strlwr()

c program stats