Implementation of the string.h library with additions.
This project developed its own implementation of the string.h library in the C programming language with some additions (with its own implementation of the sprintf function and some functions for processing strings from the C# language).
No. | Function | Description |
---|---|---|
1 | void *memchr(const void *str, int c, size_t n) | Searches for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to, by the argument str. |
2 | int memcmp(const void *str1, const void *str2, size_t n) | Compares the first n bytes of str1 and str2. |
3 | void *memcpy(void *dest, const void *src, size_t n) | Copies n characters from src to dest. |
4 | void *memmove(void *dest, const void *src, size_t n) | Another function to copy n characters from src to dest. |
5 | void *memset(void *str, int c, size_t n) | Copies the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str. |
6 | char *strcat(char *dest, const char *src) | Appends the string pointed to, by src to the end of the string pointed to by dest. |
7 | char *strncat(char *dest, const char *src, size_t n) | Appends the string pointed to, by src to the end of the string pointed to, by dest up to n characters long. |
8 | char *strchr(const char *str, int c) | Searches for the first occurrence of the character c (an unsigned char) in the string pointed to, by the argument str. |
9 | int strcmp(const char *str1, const char *str2) | Compares the string pointed to, by str1 to the string pointed to by str2. |
10 | int strncmp(const char *str1, const char *str2, size_t n) | Compares at most the first n bytes of str1 and str2. |
11 | char *strcpy(char *dest, const char *src) | Copies the string pointed to, by src to dest. |
12 | char *strncpy(char *dest, const char *src, size_t n) | Copies up to n characters from the string pointed to, by src to dest. |
13 | size_t strcspn(const char *str1, const char *str2) | Calculates the length of the initial segment of str1 which consists entirely of characters not in str2. |
14 | char *strerror(int errnum) | Searches an internal array for the error number errnum and returns a pointer to an error message string. You need to declare macros containing arrays of error messages for mac and linux operating systems. Error descriptions are available in the original library. Checking the current OS is carried out using directives. |
15 | size_t strlen(const char *str) | Computes the length of the string str up to but not including the terminating null character. |
16 | char *strpbrk(const char *str1, const char *str2) | Finds the first character in the string str1 that matches any character specified in str2. |
17 | char *strrchr(const char *str, int c) | Searches for the last occurrence of the character c (an unsigned char) in the string pointed to by the argument str. |
18 | size_t strspn(const char *str1, const char *str2) | Calculates the length of the initial segment of str1 which consists entirely of characters in str2. |
19 | char *strstr(const char *haystack, const char *needle) | Finds the first occurrence of the entire string needle (not including the terminating null character) which appears in the string haystack. |
20 | char *strtok(char *str, const char *delim) | Breaks string str into a series of tokens separated by delim. |
No. | Specifier | sprintf output | sscanf output |
---|---|---|---|
1 | c | Character | Character |
2 | d | Signed decimal integer | Signed decimal integer |
3 | i | Signed decimal integer | Signed integer (may be decimal, octal or hexadecimal) |
4 | e | Scientific notation (mantissa/exponent) using e character (the output of the numbers must match up to e-6) | Decimal floating point or scientific notation (mantissa/exponent) |
5 | E | Scientific notation (mantissa/exponent) using E character | Decimal floating point or scientific notation (mantissa/exponent) |
6 | f | Decimal floating point | Decimal floating point or scientific notation (mantissa/exponent) |
7 | g | Uses the shortest representation of decimal floating point | Decimal floating point or scientific notation (mantissa/exponent) |
8 | G | Uses the shortest representation of decimal floating point | Decimal floating point or scientific notation (mantissa/exponent) |
9 | o | Unsigned octal | Unsigned octal |
10 | s | String of characters | String of characters |
11 | u | Unsigned decimal integer | Unsigned decimal integer |
12 | x | Unsigned hexadecimal integer | Unsigned hexadecimal integer (any letters) |
13 | X | Unsigned hexadecimal integer (capital letters) | Unsigned hexadecimal integer (any letters) |
14 | p | Pointer address | Pointer address |
15 | n | Number of characters printed until %n occurs | Number of characters scanned until %n occurs |
16 | % | Character % | Character % |
No. | Flags | Description |
---|---|---|
1 | - | Left-justify within the given field width; Right justification is the default (see width sub-specifier). |
2 | + | Forces to precede the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a -ve sign. |
3 | (space) | If no sign is going to be written, a blank space is inserted before the value. |
4 | # | Used with o, x or X specifiers the value is preceded with 0, 0x or 0X respectively for values different than zero. Used with e, E and f, it forces the written output to contain a decimal point even if no digits would follow. By default, if no digits follow, no decimal point is written. Used with g or G the result is the same as with e or E but trailing zeros are not removed. |
5 | 0 | Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier). |
No. | Function | Description |
---|---|---|
1 | void *to_upper(const char *str) | Returns a copy of string (str) converted to uppercase. In case of any error, return NULL |
2 | void *to_lower(const char *str) | Returns a copy of string (str) converted to lowercase. In case of any error, return NULL |
3 | void *insert(const char *src, const char *str, size_t start_index) | Returns a new string in which a specified string (str) is inserted at a specified index position (start_index) in the given string (src). In case of any error, return NULL |
4 | void *trim(const char *src, const char *trim_chars) | Returns a new string in which all leading and trailing occurrences of a set of specified characters (trim_chars) from the given string (src) are removed. In case of any error, return NULL |
Гатоваа!!