Programming in "C‟ | Describe following functions with its syntax and example: (i) strcmp( ) (ii) strlen( )

(i) strcmp( ) : It is a string function, which is used to compare the contents of two strings. It returns 0 if both string are equal. Otherwise it returns the numerical difference between the ascii values of the first non matching pair of characters. 

Syntax:

strcmp(string1,string2); 

Eg:

if s1="there" and s2="their" the output of strcmp(s1,s2) will be 9 as

the difference between ascii values of 'r' and 'i' is 9.  

(ii) strlen() :  

strlen() is a string function which is used to find length of the string. 

Syntax : 

strlen(string) 

Example: If str contains "abcd" as its contents, strlen(str) will return 4 as length of str. 

 

Post a Comment

0 Comments