/
solidbase
/
C3_s21_stringplus
Обзор
Документация
Войти
/
solidbase
/
C3_s21_stringplus
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/s21_string.h
129 строк
5 KB
Raccoon Stefani
Add tests
01 фев 2026, 17:16
01 фев 2026, 17:16
03a3619
Код
Авторство
О чём код?
#ifndef S21_STRING_H #define S21_STRING_H #include <stdio.h> #include <stdlib.h> //------------------------------------------------------------------------------ // Part 1. Implementation of the string.h library functions //------------------------------------------------------------------------------ //--------------- string.h Types and macros ------------------------------------ // This is the unsigned integral type and is the result of the sizeof keyword. typedef long unsigned s21_size; // This macro is the value of a null pointer constant. #define S21_NULL ((void*)0) //--------------- string.h Functions ------------------------------------------- // 1. 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. void* s21_memchr(const void* str, int c, s21_size n); // 2. Compares the first n bytes of str1 and str2. int s21_memcmp(const void* str1, const void* str2, s21_size n); // 3. Copies n characters from src to dest. void* s21_memcpy(void* dest, const void* src, s21_size n); // 4. Copies the character c (an unsigned char) to the first n characters of the // string pointed to, by the argument str. void* s21_memset(void* str, int c, s21_size n); // 5. Appends the string pointed to, by src to the end of the string pointed to, // by dest up to n characters long. char* s21_strncat(char* dest, const char* src, s21_size n); // 6. Searches for the first occurrence of the character c (an unsigned char) in // the string pointed to, by the argument str. char* s21_strchr(const char* str, int c); // 7. Compares at most the first n bytes of str1 and str2. int s21_strncmp(const char* str1, const char* str2, s21_size n); // 8. Copies up to n characters from the string pointed to, by src to dest. char* s21_strncpy(char* dest, const char* src, s21_size n); // 9. Calculates the length of the initial segment of str1 which consists // entirely of characters not in str2. s21_size s21_strcspn(const char* str1, const char* str2); // 10. 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. char* s21_strerror(int errnum); // 11. Computes the length of the string str up to but not including the // terminating null character. s21_size s21_strlen(const char* str); // 12. Finds the first character in the string str1 that matches any character // specified in str2. char* s21_strpbrk(const char* str1, const char* str2); // 13. Searches for the last occurrence of the character c (an unsigned char) in // the string pointed to by the argument str. char* s21_strrchr(const char* str, int c); // 14. Finds the first occurrence of the entire string needle (not including the // terminating null character) which appears in the string haystack. char* s21_strstr(const char* haystack, const char* needle); // 15. Breaks string str into a series of tokens separated by delim. char* s21_strtok(char* str, const char* delim); //------------------------------------------------------------------------------ // Part 2. Partial implementation of the sprintf function // The next partial formatting must be supported: // Specifiers: c, d, f, s, u, % // Flags: -, +, (space) // Width description: (number) // Precision description: .(number) // Length description: h, l //------------------------------------------------------------------------------ // Part 3. Bonus. Implementation of some format modifiers of the sprintf // function The next additional format modifiers must be supported: // Specifiers: g, G, e, E, x, X, o, p // Flags: #, 0 // Width description: * // Precision description: .* // Length description: L //------------------------------------------------------------------------------ int s21_sprintf(char* str, const char* format, ...); //------------------------------------------------------------------------------ // Part 4. Bonus. Implementation of the sscanf function // The sscanf function from the stdio.h library: //------------------------------------------------------------------------------ int s21_sscanf(const char* str, const char* format, ...); //------------------------------------------------------------------------------ // Part 5. Bonus. Implementation of special string processing functions // Special string processing functions (from the String class in C#) //------------------------------------------------------------------------------ // Returns a copy of string (str) converted to uppercase. In case of any error, // return NULL. void* s21_to_upper(const char* str); // Returns a copy of string (str) converted to lowercase. In case of any error, // return NULL. void* s21_to_lower(const char* str); // 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. void* s21_insert(const char* src, const char* str, s21_size start_index); // 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. void* s21_trim(const char* src, const char* trim_chars); #endif // End of S21_STRING_H