Codeforcoding

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>

strlen string function in C programming language
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
Exit mobile version