C strlen() function to get the string length

strlen( ) function definition – In C, strlen( ) function is used to calculate the length of the string. It means that it counts the total number of characters present in the string which includes alphabets, numbers, and all special characters including blank spaces. It’s syntax is as follows –

    n = strlen(string);

Here ‘n‘ is an integer variable, which receives the values of the length of the string. The argument may be a string constant also. The counting ends at the first null character.
Example of strlen() function in C is –

   nm = study street;
   n = strlen(nm);

Sample program of C, strlen( ) function to calculate string length C

/* Sample C strlen() program */

void main()
	char nm[20];
	int length;
    printf("Enter your name");
    length=strlen(nm);   /* will feed the lenght of the string in variable */
    printf("Length of the entered string is %d", length);

Enter a string – study street

Length of the string is 12

yashan has written 69 articles

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>