Program to Find Length of String Without using strlen ()

Last Updated on

Whenever we are asked to write a program to find length of string, we make use of inbuilt function- strlen (). Obviously, it is the easy method and we can use that. But sometimes, we are asked not to use the strlen (). This program helps to find length of string without using strlen ().

#include <stdio.h>

#include<conio.h>

 

main()

{

char str[20];

int i = 0;

 

printf(“\nEnter any string: “);

gets(str);

 

while (str[i] != ‘\0’)

i++;

 

printf(“\nLength of string: %d”, i);

getch();

}

resume

Mohit Arora
Follow me