C++ Program to Find Length of String Without Using Library Function

Here you will get C++ program to find length of a string without using library function.

We iterate through the string until null character ‘\0’ is encountered and increase a counter variable for each iteration. Finally print the counter variable, it contains the length of string.

Output

Enter a string:hello hi

Length of the string ‘hello hi’ is 8

7 thoughts on “C++ Program to Find Length of String Without Using Library Function

  1. tushar

    hey, i get a error that “gets should have a prototype”.

    Reply
    1. Mohd Isa

      I guess you did not read the title of the blog. It clearly says “Without using Library functions”. The function “strlen()” is library function.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.