Friday, November 23, 2012

WRITE A FUNCTION TO FIND THE LENGTH OF A STRING.


/*   WRITE A FUNCTION TO FIND THE LENGTH OF A STRING. */

#include<stdio.h>
#include<conio.h>

#define MAX 50

int length(char *p)
{
            int len;
            for(len=0 ; *p!='\0' ; p++,len++);
            return len;
}

void main()
{
            char str[MAX];
            clrscr();
            printf("Enter a string : ");
            gets(str);
            printf("\n\tThe length of the string is %d ",length(str));
            getch();
}








/*
            =====OUT PUT=====

            Enter a string : KAUNDINYA

                    The length of the string is 9
*/

0 comments:

Post a Comment