beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
    • Learn jQuery
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

C strlen() Function – C tutorial

By Chaitanya Singh | Filed Under: C library functions

The function strlen() returns the length (number of characters) of the given string.

Function strlen() Declaration

size_t strlen(const char *str)

str – This is the given string for which we need to compute the length

Return value of strlen()

This function returns the integer value representing the number of characters in the given string.

C strlen() example

#include <stdio.h>
#include <string.h>
int main () {
   char str[50]; 
   int length;

   strcpy(str, "Welcome to Beginnersbook.com");

   //returns the number of characters in the string 
   length = strlen(str);
   
   printf("Length of string - %s is: %d", str, length);
   return 0;
}

Output:

Length of string - Welcome to Beginnersbook.com is: 28

Related Posts:

  1. C – strcoll() function
  2. C – strcpy() example
  3. C – strspn() function
  4. C – strstr() function

Leave a Reply Cancel reply

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

C Programming Tutorial

  • Turbo C++ installation
  • First C Program
  • C - Keywords
  • Operator precedence
  • C - if statement
  • C - if..else
  • C - for loop
  • C - while loop
  • C - do while loop
  • C - continue
  • C - break statement
  • C - switch..case
  • C - goto statement
  • C - Arrays
  • 2 D array
  • C - String
  • C - functions
  • Function call by reference
  • Function call by value
  • Array to function
  • C - Structures
  • C - Pointers
  • Pointer to Pointer
  • Pointers to functions
  • C - function pointers
  • Pointer & Array
  • C - File I/O
  • C Programming Examples

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap