C Program to find the length of a string without using strlen function


In this program, You will learn how to find the length of a string without using strlen function in c.


int len = strlen( str );

Example: How to find the length of a string without using strlen function in c.

#include<stdio.h>

int main() {

   char str[100];
   int len = 0;

   printf("Enter any string:");
   scanf("%[^\n]%*c", str); 

   while (str[len] != '\0') {
       len++;
   }

   printf("Length of string is:%d", len);

   return 0;
}

Output:

Enter any string:Xiith.com
Length of string is:9