String H Library Overview v3
String H Library Overview v3
h Library in C
1. strlen() - Returns the length of a string, not counting the null terminator.
8. strcoll() - Compares two strings based on the current locale's collation order.
11. strspn() - Returns the length of the initial segment of a string that consists only of characters found in another string.
12. strcspn() - Returns the length of the initial segment of a string that does not contain characters from another string.
13. strpbrk() - Finds the first character in one string that matches any character in another string.
16. strdup() - Duplicates a string by allocating new memory and copying the string into it.
19. memmove() - Similar to memcpy(), but handles overlapping memory areas safely.
23. strerror() - Returns a pointer to the textual description of the current errno value.
24. strxfrm() - Transforms a string based on the current locale's collation rules.
26. memccpy() - Copies bytes from one memory location to another, stopping after a specified byte is found.
string lexicographically, while strncmp() compares only up to a specified number of characters. strcoll() uses the locale
settings for collation and can behave differently depending on language/locale rules.
String Searching and Finding Substrings: strchr(), strrchr(), strstr(), and strpbrk() are used for finding characters or
substrings in strings. strchr() and strrchr() find the first or last occurrence of a character, respectively. strstr() looks for a
substring, and strpbrk() finds the first match of any character from a set.
String Tokenization: strtok() is used for breaking a string into tokens based on delimiters. This is useful for parsing
Memory Functions: Functions like memset(), memcpy(), memmove(), and memcmp() operate directly on blocks of
memory rather than strings. These are often used in low-level operations like copying memory or comparing chunks of
data.
String Duplication and Transformation: strdup() duplicates a string (i.e., it allocates memory and copies the string into it),
Error Handling: strerror() returns a human-readable description of an error based on the errno value.
Null Terminator: C strings are null-terminated, meaning they end with the special character '\0' (null terminator).
Functions like strlen() rely on this null terminator to determine the end of a string.
Buffer Overflows: Functions like strcpy() and strcat() do not check if the destination buffer is large enough to hold the
result. Always ensure that your destination string has enough space to avoid memory overflow.
Memory Allocation: Some functions like strdup() and malloc() involve dynamic memory allocation, which requires careful
String vs Array of Characters: A string in C is just a pointer to a character array. Most string functions operate on