Program for calculating length of a string using user defined function.

#include <stdio.h>
int strlen(char *);

int main()
{
char c[50];
int d;

printf("Enter a string: ");
scanf("%s",c);

d=strlen(c);
printf("String length: %d\n%s\n",d,c);

return 0;
}

int strlen(char *p)
{
int j=0;

while(*p!='')
{
j++;
p++;
}

return j;
}

Advertisements

2 thoughts on “Program for calculating length of a string using user defined function.

  1. #include
    #include

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

    printf(“Enter a string to calculate it’s length\n”);
    gets(a);

    length = strlen(a);

    printf(“Length of entered string is = %d\n”,length);

    return 0;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s