Saturday 11 November 2017

C Program to Find the Length of a String without using the Built-in Function


Code:

#include

void main()
{
    char string[50];
    int i, length = 0;

    printf("Enter a string \n");
    gets(string);
    /*  keep going through each character of the string till its end */
    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
ExecuteCodes
The length of a string is the number of characters in it
So, the length of ExecuteCodes = 12

More C Programs











100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...