strlen(): String Length in C Programming

In C programming, we use strlen() to find the length of the string. String handling function strlen() returns the number of characters in string.

strlen() Syntax


integer_variable = strlen(string or string_variable);

strlen() Examples


#include<stdio.h>
#include
	
int main()
{
 char str[30];
 int len;

 printf("Enter string:\n");
 gets(str);
 
 len = strlen(str);
 
 printf("Length of given string is: %d", len);

 return 0;
}

strlen() Program Output

Enter string:
Welcome to C↲
Length of given string is: 12

Note: ↲ indicate ENTER is pressed.