How to find the length of string by using c program?

How to find the length of the string by using c program?

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() function.

How to find the length of string by using c program?
















#include <stdio.h>
int main()
{
    char s[1000];
    int i;

    printf("Enter a string: ");
    scanf("%s", s);

    for(i = 0; s[i] != '\0'; ++i);

    printf("Length of string: %d", i);
    return 0;

}

Comments