C Program to Find the Length of a String

C Programming Language / String in C Language

722

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

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.


This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.