C Program to Find String Length Without Using strlen

This C program finds string length in a given string without using string handling function strlen().

C Source Code: String Length Without strlen()


#include<stdio.h>

int main()
{
char str[30];
int i, len=0;

printf("Enter string:\n");
gets(str);

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

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

return 0;
}

Output

Enter string:
Welcome to C ↲
Length of given string is: 12

Note: ↲ represents ENTER key is pressed.