February 23, 2025

Telugu Tech Tuts

TimeComputers.in

C language tutorial in telugu free download Part 35

C language tutorial in telugu free download

Description

The C library function size_t strlen(const char *str) computes the length of the string str up to but not including the terminating null character.

Declaration

Following is the declaration for strlen() function.

size_t strlen(const char *str)

Parameters

  • str — This is the string whose length is to be found.

Return Value

This function returns the length of string.

Example

The following example shows the usage of strlen() function.

#include <stdio.h>
#include <string.h>

int main ()
{
   char str[50];
   int len;

   strcpy(str, "This is tutorialspoint.com");

   len = strlen(str);
   printf("Length of |%s| is |%d|n", str, len);

   return(0);
}

Let us compile and run the above program, this will produce the following result:

Length of |This is tutorialspoint.com| is |26|

Explanation of Program :

In the above program we have accepted the string from the user.

After that we have initialized the length variable with zero. “length” variable is used to keep track of the number of character accessed.
Initially length is 0. Now we are accessing very first character. If it is equal to NULL then we are terminating the loop else we are incrementing the length.