The library or built-in functions strlen(),
strcpy(), strcat(), strcmp(), strrev() etc are used for string manipulation in
C. These functions are defined in header file string.h. They are described in
detail as follow.
i.
strlen()
This function
returns the length of string. Its prototypes is as
int strlen(string s1);
example:
|
ii.
strcpy()
This function is used to copy one string
to another. It is called as
strcpy(destination_string,
source_string);
Thus, strcpy(s1,s2) means
the content of s2 is copied to s1.
An example:
|
iii.
strcat()
This function concatenates the source string at the end of the destination or target string. An example
|
iv. strcmp();
This function compares two
strings to find out whether they are same or different. The two strings are
compared character by character until there is a mismatch or end of one of
stings is reached. It two strings are equal, it returns zero, otherwise, it
returns the difference between the ASCII values of the first non-matching pair
of characters
An example.
|
v.
strrev();
This function is used to reverse all characters in a string except null character at the end of string. The reverse of string “abc” is “cba”.
|
Comments
Post a Comment