Google News
logo
C program to find the length of a String without using function strlen()
The following C program we are counting the number of characters in a given String to find out and display its length on console.

C Program – finding length of a String without using standard library function strlen :

Program :
#include <stdio.h>
int main()
{
    /* Here we are taking a char array of size 
     * 160 which means this array can hold a string 
     * of 160 chars. You can change this as per requirement
     */
    char str[160],i;
    printf("Enter a string: \n");
    scanf("%s",str);

    // '\0' represents end of String
    for(i=0; str[i]!='\0'; ++i);
       printf("\nLength of input string: %d",i);
    
    return 0;
}
Output :
Enter a string: 
FreeTimeLearn
Length of input string: 13