C program to find length of string without using library function

C program to find length of string without using library function:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>

main()
{
   char str[100];
   int length;

   printf("Enter the String : ");
   gets(str);

   length = 0;

   while (str[length] != '\0')
      length++;
   printf("\nLength of the String is : %d",length);
}

OUTPUT:

Enter the String : BaronTuts

Length of the String is : 9

 

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.