Q26 Write a program in C to find the length of a string without using library function.

Admin

Write a program in C to find the length of a string without using library function.

#include <stdio.h>
void main()
{
    char string[50];
    int i, length = 0;
    printf("Enter a string \n");
    gets(string);
    for (i = 0; string[i] != '\0'; i++)
    {
        length++;
    }
    printf("The length of a string is the number of characters in it \n");
    printf("So, the length of %s = %d\n", string, length);
}

Output

Enter a string 
Hello How are You !
The length of a string is the number of characters in it 
So, the length of Hello How are You ! = 19

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.