C Program to Find the Length of a String

In this article, you'll learn to find the length of a string without using strlen() function.

To understand this example, you should have the knowledge of following C programming topics:

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.

Example: Calculate Length of String without Using strlen() Function

#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;


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.