Skip to main content

C Program to find length of string with or without function

//Program Name: To find length of the string with and without function.

#include<stdio.h>
#include<string.h>
void main()
{
char str[250]; //to store entered string
int cnt;  //counter

printf("\n\tEnter a string to check length:" );
gets(str);

for(cnt = 0; str[cnt] != '\0'; ++cnt);

printf("\n\t Length of string without using function: %d", cnt);

printf("\n\t Length of string with strlen function %d",strlen(str));

}

Output

Enter a string to check length:Learning C
Length of string without using function: 10
	 Length of string with strlen function 10