fastread homefastrread library fastread menu

C : Find the Length of a String

Tutorial by:Manisha Dubey      Date: 2016-06-17 04:32:57

❰ Previous Next ❱

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.

Source Code to Calculated Length without Using strlen() Function

#include <stdio.h>
int 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);
    return 0;
}

Output

Enter a string: Programiz
Length of string: 9

 

 
 

This program asks user to enter a string and computes the length of string manually using for loop.

❰ Previous Next ❱


C

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website