Find Length of string in C is a program to find a length that is a total number of characters in the string including space.

String in c
String in c is a collection of characters. And it ends with the null character.
In c string has different string functions such as strcmp, strrev, strlen etc.

String length in c
To find the length of the string in c the string class provided one function strlen () using this function we can find the length of the string.
Syntax for String length
strlen in c to find the length of a string in c.
int len = strlen(string);
This function returns an integer value which is a length of the string.

Strlen example in c :-
strlen(“technical”);
The length of sting is 9

Algorithm to find length of string in c

  1. Declare variable. str, len
  2. Take string input from user. str
  3. Find length of the string using string function
    int len = strlen(str);
  4. Print the length of the string. len

C program to find length of the string using strlen in c.

#include<stdio.h>

#include<string.h>

main()

{

char str[100];

int len;

printf("Enter a string to know the length\n");

gets(str);

len=strlen(str);

printf("The length of %s is %d\n",str,len);

}

Output :

find length of string in c

Write A Comment