Pages

Saturday, 20 June 2015

User defined string length function

User defined string length function to calculate length of any string

Coding:

#include<stdio.h>
int mystrlen(char *s)
{
int i;
for(i=0;s[i]!='\0';i++);
return i;
}

int main()
{
char b[30];
printf("Please enter the string:");
gets(b);
printf("Length is:%d",mystrlen(b));
return 0;
}

Output:
Please enter the string:Programming
Length is:11