This Markdown document provides documentation for a set of custom string and memory functions implemented in C.
The following functions are custom implementations of commonly used string and memory functions found in the C Standard Library. These functions provide functionality for string manipulation, comparison, and memory operations.
unsigned char my_strlen(const char *str);
- Description: Computes the length of the input string.
- Parameters:
str
: A pointer to the null-terminated string.
- Returns: The length of the string.
char *my_strcpy(char *destAdd, const char *srcAdd);
- Description: Copies the source string to the destination string.
- Parameters:
destAdd
: A pointer to the destination string.srcAdd
: A pointer to the source string.
- Returns: A pointer to the destination string (
destAdd
).
char *my_strncpy(char *destAdd, const char *srcAdd, char n_Copy);
- Description: Copies at most
n_Copy
characters from the source string to the destination string. - Parameters:
destAdd
: A pointer to the destination string.srcAdd
: A pointer to the source string.n_Copy
: The maximum number of characters to copy.
- Returns: A pointer to the destination string (
destAdd
).
char *my_strcat(char *destAdd, const char *srcAdd);
- Description: Concatenates the source string to the end of the destination string.
- Parameters:
destAdd
: A pointer to the destination string.srcAdd
: A pointer to the source string.
- Returns: A pointer to the destination string (
destAdd
).
char *my_strncat(char *destAdd, const char *srcAdd, char n_Copy);
- Description: Concatenates at most
n_Copy
characters from the source string to the end of the destination string. - Parameters:
destAdd
: A pointer to the destination string.srcAdd
: A pointer to the source string.n_Copy
: The maximum number of characters to concatenate.
- Returns: A pointer to the destination string (
destAdd
).
int my_strcmp(const char *str1Add, const char *str2Add);
- Description: Compares two strings lexicographically.
- Parameters:
str1Add
: A pointer to the first string.str2Add
: A pointer to the second string.
- Returns: An integer indicating the comparison result: 0 if equal, negative if
str1Add
is less thanstr2Add
, and positive ifstr1Add
is greater thanstr2Add
.
int my_strncmp(const char *str1Add, const char *str2Add, char n_Copy);
- Description: Compares at most
n_Copy
characters of two strings lexicographically. - Parameters:
str1Add
: A pointer to the first string.str2Add
: A pointer to the second string.n_Copy
: The maximum number of characters to compare.
- Returns: An integer indicating the comparison result: 0 if equal, negative if
str1Add
is less thanstr2Add
, and positive ifstr1Add
is greater than `
str2Add`.
char *my_strchr(const char *strAdd, int wantedChar);
- Description: Searches for the first occurrence of
wantedChar
in the string. - Parameters:
strAdd
: A pointer to the null-terminated string.wantedChar
: The character to search for.
- Returns: A pointer to the first occurrence of
wantedChar
in the string, orNULL
if not found.
char *my_strrchr(const char *strAdd, int wantedChar);
- Description: Searches for the last occurrence of
wantedChar
in the string. - Parameters:
strAdd
: A pointer to the null-terminated string.wantedChar
: The character to search for.
- Returns: A pointer to the last occurrence of
wantedChar
in the string, orNULL
if not found.
char *my_strstr(const char *haystack, const char *needle);
- Description: Searches for the first occurrence of
needle
inhaystack
. - Parameters:
haystack
: A pointer to the null-terminated string to search in.needle
: A pointer to the null-terminated string to search for.
- Returns: A pointer to the first occurrence of
needle
inhaystack
, orNULL
if not found.
unsigned int my_strcspn(const char *str1Add, const char *str2Add);
- Description: Computes the length of the initial segment of
str1Add
that consists of characters not instr2Add
. - Parameters:
str1Add
: A pointer to the null-terminated string.str2Add
: A pointer to the null-terminated string containing characters to be excluded.
- Returns: The length of the initial segment.
unsigned int my_strspn(const char *str1Add, const char *str2Add);
- Description: Computes the length of the initial segment of
str1Add
that consists of characters instr2Add
. - Parameters:
str1Add
: A pointer to the null-terminated string.str2Add
: A pointer to the null-terminated string containing characters to be included.
- Returns: The length of the initial segment.
char *my_strpbrk(const char *str1Add, const char *str2Add);
- Description: Searches
str1Add
for any character fromstr2Add
. - Parameters:
str1Add
: A pointer to the null-terminated string to search in.str2Add
: A pointer to the null-terminated string containing characters to search for.
- Returns: A pointer to the first occurrence of any character from
str2Add
instr1Add
, orNULL
if not found.
void *my_memset(void *strAdd, int targetChar, size_t numOfChar);
- Description: Sets the first
numOfChar
bytes of the memory pointed to bystrAdd
to the specifiedtargetChar
. - Parameters:
strAdd
: A pointer to the memory to be set.targetChar
: The character to set.numOfChar
: The number of bytes to set.
- Returns: A pointer to the original memory.
int my_memcmp(const void *str1Add, const void *str2Add, size_t numOfChar);
- Description: Compares the first
numOfChar
bytes of two memory regions. - Parameters:
str1Add
: A pointer to the first memory region.str2Add
: A pointer to the second memory region.numOfChar
: The number of bytes to compare.
- Returns: An integer indicating the comparison result: 0 if equal, negative if
str1Add
is less thanstr2Add
, and positive ifstr1Add
is greater thanstr2Add
.
void *my_memcpy(void *destAdd, const void *srcAdd, size_t numOfChar);
- Description: Copies
numOfChar
bytes from the source memory region to the destination memory region. - Parameters:
destAdd
: A pointer to the destination memory region.srcAdd
: A pointer to the source memory region.numOfChar
: The number of bytes to copy.
- Returns: A pointer to the destination memory region (
destAdd
).
void *my_memmove(void *destAdd, const void *srcAdd, size_t numOfChar);
- Description: Safely copies
numOfChar
bytes from the source memory region to the destination memory region, even if the regions overlap. - Parameters:
destAdd
: A pointer to the destination memory region.srcAdd
: A pointer to the source memory region.numOfChar
: The number of bytes to copy.
- Returns: A pointer to
the destination memory region (destAdd
).
void *my_memchr(const void *strAdd, int wantedChar, size_t numOfChar);
- Description: Searches for the first occurrence of
wantedChar
in the memory region. - Parameters:
strAdd
: A pointer to the memory region.wantedChar
: The character to search for.numOfChar
: The number of bytes to search within.
- Returns: A pointer to the first occurrence of
wantedChar
in the memory region, orNULL
if not found.
These custom functions provide basic string and memory manipulation capabilities. They are intended for educational purposes and may not be as efficient or robust as standard library functions.
Feel free to use this documentation as a reference for your custom C functions. You can further enhance it by providing more details, examples, and explanations as needed.