C program to calculate length of a String

strlen – calculate the length of a string

If you are implementing some C program dealing with character string, its most likely that at some point of time, you need to know what is the total number of characters in this string. C’s provides a standard library function “strlen” to know this.

$ vim strlength.c
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
    char *helloworld = "Helloworld";
    printf("No. of Characters in helloworld are : %d\n", (int)strlen(helloworld));
    return 0;

As, we can see, we could identify total number of characters in string which is length of string using strlen API.

The description of strlen as per library is as below,

#include <string.h>
size_t strlen(const char *s);

The strlen() function calculates the length of the string s, excluding the terminating null byte (‘\0’).

Related :   How to resolve "cc1: all warnings being treated as errors" ?

The strlen() function returns the number of bytes in the string s.


Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )


Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded