C program to calculate the length of a string using C string Functions

This program will ask the user to input a string. The program will implement the strlen() function to calculate the length and will return the result to the user.

Loading…

For understanding this topic more clearly you must have the prior knowledge of the following topics.

How to calculate the length of the string using strlen() function?

The following code implements the strlen() function for calculating the length of characters in the string entered by users. The use of the string function makes the code more efficient and less time-consuming.

Code:

#include
#include
int main(){
        char n[100];
        int l;
        puts("Enter the string: ");
        gets(n);
        l=strlen(n);
        printf("Total character or length of the string = %d",l);
}

Output:

Enter the string:
house
Total character or length of the string = 5

 

Loading…