Tuesday, 27 August 2013

write an c function to calculate string length

/*
    Date: 17/08/13 08:46
    Description: This is developed as an alternatove to string functions present in standered library
*/


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int stringlen(char *);  //return the lenght of the string

int main()
{
    char str[]="\0";
    int k=0;
   
    printf("enter your string:");
    gets(str);
    //scanf("%s",str);
    k=stringlen(str);
    printf("string lenght=%d",k);
   
   
    return 0;
}


int stringlen(char *temp)
{
    int count=0;
    while(*temp) count++,temp++;
   
    return(count);
}

No comments:

Post a Comment