String Handling
There is no
basic type for strings in C. A string is simply a sequence of
characters ending with the string terminator, stored in a
char array. A string is represented by a
char pointer that points to the first character in
the string.
The customary functions for manipulating strings are declared in string.h . Those functions that modify a string return a pointer to the modified string. The functions used to search for a character or a substring return a pointer to the occurrence found, or a null pointer if the search was unsuccessful.
-
char *strcat( char *s1, const char *s2); Appends the string
s2to the end ofs1. The first character copied froms2replaces the string terminator character ofs1.-
char *strchr( const char *s, intc); Locates the first occurrence of the character
cin the strings.-
intstrcmp( const char *s1, const char *s2); Compares the strings
s1ands2, and returns a value that is greater than, equal to, or less than0to indicate whethers1is greater than, equal to, or less thans2. A string is greater than another if the first character code in it which differs from the corresponding character code in the other string is greater than that character code.-
intstrcoll( const char *s1, const char *s2); Transforms an internal copy of the strings
s1ands2using the functionstrxfrm(), then compares them usingstrcmp()and returns the result.-
char *strcpy( char *s1, const char *s2); Copies
s2to thechararray referenced bys1. This ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access