strlen string function in C programming language
- Home
- function in C
- strlen string function in C programming language
- On
- By
- 0 Comment
- Categories: function in C, Pre-define String function in C
strlen string function in C programming language
strlen string function in C programming language
In this article, we will learn about strlen string function in C programming language and its functionality.
Description
strlen() string function 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 function calculates the length of a given String(String length)
Declaration
The declaration for strlen() function in the C language is
size_t strlen(const char *str);
Parameters or Arguments
str – This is the string, whose length is to be calculated.
Returns
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.
Required Header
In C Programming language, the required header for strlen() String function is
#include<string.h>
strlen string – example
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 which are similar to the this function
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