C program to find length of the string using pointer

C program to find length of the string using pointer:
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>
#include<conio.h>

int str_len(char*);
main()
{
   char str[20];
   int length;

   printf("Enter any string :");
   gets(str);

   length=str_len(str);
   printf("The length of the string %s is : %d",str,length);
}

int str_len(char*p)
{
   int count = 0;
   while(*p != '\0')
    {
      count++;
      p++;
    }
   return count;
}

OUTPUT:

Enter any string :BaronTuts
The length of the string BaronTuts 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.