In this article, we will learn about strlen string function in C programming language and its functionality.
strlen() in C programming language returns the length of the string passed as arguments(pointed to by str). but not include the ending null character.
strlen() – this is calculates the length of a given String(String length)
The declaration for strlen() in the C language is
size_t strlen(const char *str);
str – This is the string, whose length is to be calculated.
the strlen() function returns the length of the given string or pointed to by str. It does not include the null character in the length calculation.
In C Programming language, the required header for strlen() is
#include<string.h>
Program 1
#include <stdio.h> #include <string.h> int main() { char firstString[20]="Hello my friends"; char secondString[20]={'H','e','l','l','o','o'}; char thirdString[20]; printf("\n\nEnter your String\n\n"); gets(thirdString); printf("\nLength of first string:%d\n",strlen(firstString)); printf("\nLength of second string:%d\n",strlen(secondString)); printf("\nLength of first string:%d\n",strlen(thirdString)); return 0; }
When above program me is compiled it will produce the following result
Enter your String Hello world Length of first string :16 Length of second string :6 Length of third string :11
There are other C programming language functions that are similar to the this function
strrev() function in C language
strrchr() function in C language
strdup() function in C language
strlwr() function in C language
strupr() function in C language
strrev() function in C language
strset() function in C language
strnset() function in C language
strtok() function in C language
strcat() function in C language
strncat() function in C language
strcpy() function in C language
strncpy() function in C language
strcmp() function in C language
strchr () function in C language
strdub () function in C language
Suggested for you
String handling in C programming language
User defined function in C language
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…