Friday, June 20, 2014

Functions to calculate string length using arrays

There are many programs in which we need to calculate the length of a string. To calculate string length we can use built in function in C Programming to calculate length but we should know what is going on in back end of this function or what is the structure of this function? The following code defines the structure of function used to calculate the length of a string.

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

}
int main()
{
   int a[100000];
   puts("Enter String : ");
   gets(a);
   system("pause");
   system("cls");
   printf("\n\n\nString Length is %d \n\n\n\n\n",strln(a));
}

No comments:

Post a Comment