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()  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)

Declaration

The declaration for strlen() 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()  is

#include<string.h>

Length calculation of string

strlen string function in C – 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 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 function in C Language

Arithmetic function  in C

Function in C language

String handling in C programming language

User defined function in C language

Python function 

recursive function in Python

 

String function in C programming Language
strnset string function in C programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

8 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago