View All C Programs

 Previews Example  View All C Programs Next Example 

Program to Find the Length of a String in C

You can use standard library function strlen() to find the length of a string but, this program computes the length of a string manually without using strlen() funtion.
#include <stdio.h>
#include <conio.h>
main()
{
    char s[1000],i;
    printf("Enter a string: ");
    scanf("%s",s);
    for(i=0; s[i]!='\0'; ++i);
    printf("Length of string: %d",i);
    getch();
}
Result
Enter a string: Fastlearning
Length of string: 10