Program to Calculate Length of a String (Using strlen in-built function)

#include
#include
#include
void main(){
int strlength;
char *str;
clrscr();
      printf("\nEnter the string: ");
      gets(str);
strlength=strlen(str);
printf("\nThe length of the string is %d.",strlength);
getch();
}

Output:
Enter the string: Learn C Online
The length of the string is 14.

You may also like...

5 Responses

  1. Anonymous says:

    thanx

  2. Anonymous says:

    plz post for Without using strlen().

  3. Adeel Ehsan says:

    #include
    #include
    int string_ln(char*);
    int main()
    {
    char str[20];
    int l;
    printf(“Enter any string:n : “);
    gets(str);
    l=string_ln(str);
    printf(“The length of the given string %s is : %d”,str,l);
    getch();
    }
    int string_ln(char*p) /* p=&str[0] */
    {
    int count=0;
    while(*p!=’\0′)
    {
    count++;
    p++;
    }
    return count;
    }

  1. April 12, 2015

    […] Calculate Length of a String (Using strlen in-built function) […]

  2. July 6, 2020

    […] Here is the program that demonstrate use of strlen string function – visit Find string length using in-built C string function […]

Leave a Reply

Your email address will not be published. Required fields are marked *

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet