String library function
There are several string library functions used to manipulate string and the prototypes for these functions are in header file “string.h”. Several string functions are
strlen()
This function return the length of the string. i.e. the number of characters in the string excluding the terminating NULL character. It accepts a single argument which is pointer to the first character of the string.
For example
strlen(“suresh”);
It return the value 6.
In array version to calculate legnth:
int str(char str[])
{
int i=0;
while(str[i]!=’\o’)
{
i++;
}
return i;
}
Example:
#include
strcmp()
=0 when s1=s2
>0 when s1>s2
The exact value returned in case of dissimilar strings is not defined. We only know
that if s1s2 then a positive
value will be returned.