C program to find length of string using user defined function

C program to find length of string using user defined 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>

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

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

   length=FindLen(str);

   printf("\nLength of the String is : %d",length);
}

int FindLen(char str[])
{
   int len = 0;
   while (str[len] != '\0')
      len++;
   return (len);
}

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.