Home C Programming Language / Programs / C Program to Find the Length of a String
🚀 Programming Example

C Program to Find the Length of a String

👁 867 Views
💻 Practical Program
📘 Step Learning
In this article, you'll learn to find the length of a string without using strlen() function.

💻 Program Code

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

🖥 Program Output

Enter a string: Programiz
Length of string: 9
                            

📘 Explanation

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

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.