mikroSDK Reference Manual
ANSI C String Library

ANSI C String Library. More...

Functions list

const void * memchr (const void *ptr, char ch, unsigned int num)
 Function locates the first occurrence of a character in a defined memory area starting with a given address. The function returns the pointer to this location or 0 if the n was not found. More...
 
int memcmp (const void *str1, const void *str2, int num)
 Function compares a given number of characters inside of objects pointed to by str1 and str2, returns zero if the objects are equal, or returns a difference between the first differing characters (in a left-to-right evaluation). More...
 
void * memcpy (void *dest_ptr, const void *src_ptr, int num)
 Function copies a given number of characters( num ) from the object pointed to by src_ptr into the object pointed to by dest_ptr. If copying takes place between objects that overlap, the behavior is undefined. The function returns address of the object pointed to by dest_ptr. More...
 
void * memmove (void *dest_ptr, const void *src_ptr, int num)
 Function copies num characters from a object pointed to by src_ptr into a object pointed to by dest_ptr. Unlike memcpy, the memory areas to and from may overlap. The function returns address of the object pointed to. More...
 
void * memset (void *ptr, char chr, int num)
 Function copies the value of the character into each of the first num characters of the object pointed by ptr. The function returns address of the object pointed to by ptr. More...
 
char * strcat (char *dest_ptr, const char *src_ptr)
 Function appends a copy of the string src_ptr to the string dest_ptr, overwriting the null character at the end of dest_ptr. Then, a terminating null character is added to the result. If copying takes place between objects that overlap, the behavior is undefined. The string must have enough space to store the result. The function returns address of the object pointed to by dest_ptr. More...
 
const char * strchr (const char *ptr, char chr)
 Function locates the first occurrence of character chr in the string ptr. The function returns a pointer to the first occurrence of character chr, or a null pointer if chr does not occur in ptr. The terminating null character is considered to be a part of the string. More...
 
int strcmp (const char *str1, const char *str2)
 Function compares strings str1 and str2 and returns zero if the strings are equal, or returns a difference between the first differing characters (in a left-to-right evaluation). Accordingly, the result is greater than zero if str1 is greater than str2 and vice versa. More...
 
char * strcpy (char *dest_ptr, const char *src_ptr)
 Function copies the string from src_ptr to the string dest_ptr. If copying is successful, the function returns dest_ptr. If copying takes place between objects that overlap, the behavior is undefined. More...
 
int strlen (const char *str)
 Function returns the length of the string str. (the terminating null character does not count against string's length). More...
 
char * strncat (char *dest_ptr, const char *src_ptr, int size)
 Function appends not more than size characters from the string src_ptr to dest_ptr. The initial character of src_ptr overwrites the null character at the end of dest_ptr. The terminating null character is always appended to the result. The function returns dest_ptr. More...
 
char * strncpy (char *dest_ptr, const char *src_ptr, int size)
 Function copies the string from src_ptr the string dest_ptr. If copying is successful, the function returns dest_ptr. If copying takes place between objects that overlap, the behavior is undefined. More...
 
int strspn (const char *str1, const char *str2)
 Function computes the length of the maximum initial segment of the string pointed to by str1 that consists entirely of characters that are in the string pointed to by str2. The function returns the length of the initial segment. More...
 
char strcspn (const char *str1, const char *str2)
 Function computes the length of the maximum initial segment of the string pointed to by str1 that consists entirely of characters that are not in the string pointed to by str2. The function returns the length of the initial segment. More...
 
int strncmp (const char *str1, const char *str2, char len)
 Function lexicographically compares not more than len characters (characters that follow the null character are not compared) from the string pointed by str1 to the string pointed by str2. More...
 
char * strpbrk (const char *str1, const char *str2)
 Function searches str1 for the first occurrence of any character from the string str2. The terminating null character is not included in the search. The function returns pointer to the matching character in str1. If str1 contains no characters from str2, the function returns 0. More...
 
const char * strrchr (const char *ptr, char chr)
 Function searches the string ptr for the last occurrence of character chr. The null character terminating ptr is not included in the search. The function returns pointer to the last chr found in ptr; if no matching character was found, function returns 0. More...
 
char * strstr (const char *str1, const char *str2)
 Function locates the first occurrence of the string str2 in the string str1 (excluding the terminating null character). The function returns pointer to first occurrence of str2 in str1; if no string was found, function returns 0. If str2 is a null string, the function returns 0. More...
 
char * strtok (char *str1, char *str2)
 The strtok function returns a pointer to the first character of a token, or a null pointer if there is no token. More...
 
void str_cut_chr (char *str, char num)
 The str_cut_chr function removes all selected characters from string str, and returns it to the same str without those characters. More...
 
void str_replace_chr (char *str, char chr_old, char chr_new)
 The replace_chr function replaces all chr_old characters in string str with chr_new characters and returns it to the same str. More...
 
void str_cut_left (char *str, int num)
 The function str_cut_left crops string str to the left starting from position num. More...
 
void str_cut_right (char *str, int num)
 The function str_cut_right crops string str to the right starting from position num. More...
 
void str_split (char *str1, char *str2, int num)
 The str_split function splits string str1 into two strings, str1 and str2, after the num-th character. More...
 
void str_insert_chr (char *str, char chr, int num)
 The str_insert_chr function adds selected character chr to string str at position num. More...
 

Detailed Description

ANSI C String Library provides a set of standard ANSI C library functions useful for manipulating strings and RAM memory.

Function Documentation

◆ memchr()

const void* memchr ( const void *  ptr,
char  ch,
unsigned int  num 
)

Function locates the first occurrence of a character in a defined memory area starting with a given address. The function returns the pointer to this location or 0 if the n was not found.

Parameters
[in]ptrPointer to the address from which the character is searched from.
[in]chCharacter that is searched for.
[in]numNumber of bytes in memory from the start address where the search is conducted.
Returns
Pointer to the found character.

◆ memcmp()

int memcmp ( const void *  str1,
const void *  str2,
int  num 
)

Function compares a given number of characters inside of objects pointed to by str1 and str2, returns zero if the objects are equal, or returns a difference between the first differing characters (in a left-to-right evaluation).

Parameters
[in]str1String object one.
[in]str2String object two.
[in]numNumber of characters compared.
Returns
Difference between objects (zero if equal).

◆ memcpy()

void* memcpy ( void *  dest_ptr,
const void *  src_ptr,
int  num 
)

Function copies a given number of characters( num ) from the object pointed to by src_ptr into the object pointed to by dest_ptr. If copying takes place between objects that overlap, the behavior is undefined. The function returns address of the object pointed to by dest_ptr.

Parameters
[out]dest_ptrPointer to the location data is copied to.
[in]src_ptrPointer to the location data is copied from.
[in]numNumber of bytes of data to be copied.
Returns
Pointer to the location data is copied to.

◆ memmove()

void* memmove ( void *  dest_ptr,
const void *  src_ptr,
int  num 
)

Function copies num characters from a object pointed to by src_ptr into a object pointed to by dest_ptr. Unlike memcpy, the memory areas to and from may overlap. The function returns address of the object pointed to.

Parameters
[out]dest_ptrPointer to the location data is copied to
[in]src_ptrPointer to the location data is copied from
[in]numNumber of bytes of data to be moved.
Returns
Pointer to the location data is moved to.

◆ memset()

void* memset ( void *  ptr,
char  chr,
int  num 
)

Function copies the value of the character into each of the first num characters of the object pointed by ptr. The function returns address of the object pointed to by ptr.

Parameters
[in]ptrPointer to the location from which the data will be set.
[in]chrValue to which the data will be set.
[in]numNumber of bytes that will be set.
Returns
Address of the object pointed to by ptr.

◆ strcat()

char* strcat ( char *  dest_ptr,
const char *  src_ptr 
)

Function appends a copy of the string src_ptr to the string dest_ptr, overwriting the null character at the end of dest_ptr. Then, a terminating null character is added to the result. If copying takes place between objects that overlap, the behavior is undefined. The string must have enough space to store the result. The function returns address of the object pointed to by dest_ptr.

Parameters
[out]dest_ptrAddress of destination.
[in]src_ptrAddress of source.
Returns
Address of the object pointed to by dest_ptr.

◆ strchr()

const char* strchr ( const char *  ptr,
char  chr 
)

Function locates the first occurrence of character chr in the string ptr. The function returns a pointer to the first occurrence of character chr, or a null pointer if chr does not occur in ptr. The terminating null character is considered to be a part of the string.

Parameters
[in]ptrAddress of string.
[in]chrCharacter to search for.
Returns
Address of found character.

◆ strcmp()

int strcmp ( const char *  str1,
const char *  str2 
)

Function compares strings str1 and str2 and returns zero if the strings are equal, or returns a difference between the first differing characters (in a left-to-right evaluation). Accordingly, the result is greater than zero if str1 is greater than str2 and vice versa.

Parameters
[in]str1String 1.
[in]str2String 2.
Returns
Number of different characters.

◆ strcpy()

char* strcpy ( char *  dest_ptr,
const char *  src_ptr 
)

Function copies the string from src_ptr to the string dest_ptr. If copying is successful, the function returns dest_ptr. If copying takes place between objects that overlap, the behavior is undefined.

Parameters
[out]dest_ptrAddress of destination object.
[in]src_ptrAddress of source object.
Returns
Address pointed to by dest_ptr.

◆ strlen()

int strlen ( const char *  str)

Function returns the length of the string str. (the terminating null character does not count against string's length).

Parameters
[in]strString address.
Returns
Number of characters in string str.

◆ strncat()

char* strncat ( char *  dest_ptr,
const char *  src_ptr,
int  size 
)

Function appends not more than size characters from the string src_ptr to dest_ptr. The initial character of src_ptr overwrites the null character at the end of dest_ptr. The terminating null character is always appended to the result. The function returns dest_ptr.

Parameters
[out]dest_ptrAddress of destination object.
[in]src_ptrAddress of source object.
[in]sizeNumber of characters to append.
Returns
Address pointed to by dest_ptr.

◆ strncpy()

char* strncpy ( char *  dest_ptr,
const char *  src_ptr,
int  size 
)

Function copies the string from src_ptr the string dest_ptr. If copying is successful, the function returns dest_ptr. If copying takes place between objects that overlap, the behavior is undefined

Parameters
[out]dest_ptrAddress of destination object.
[in]src_ptrAddress of source object.
[in]sizeNumber of characters to copy.
Returns
Address pointed to by dest_ptr.

◆ strspn()

int strspn ( const char *  str1,
const char *  str2 
)

Function computes the length of the maximum initial segment of the string pointed to by str1 that consists entirely of characters that are in the string pointed to by str2. The function returns the length of the initial segment.

Parameters
[in]str1Address of string 1.
[in]str2Address of string 2.
Returns
Number of characters found.

◆ strcspn()

char strcspn ( const char *  str1,
const char *  str2 
)

Function computes the length of the maximum initial segment of the string pointed to by str1 that consists entirely of characters that are not in the string pointed to by str2. The function returns the length of the initial segment.

Parameters
[in]str1Address of string 1.
[in]str2Address of string 2.
Returns
Number of characters.

◆ strncmp()

int strncmp ( const char *  str1,
const char *  str2,
char  len 
)

Function lexicographically compares not more than len characters (characters that follow the null character are not compared) from the string pointed by str1 to the string pointed by str2.

Parameters
[in]str1Address of string 1.
[in]str2Address of string 2.
[in]lenNumber of characters to compare.
Returns
Number of exact characters.

◆ strpbrk()

char* strpbrk ( const char *  str1,
const char *  str2 
)

Function searches str1 for the first occurrence of any character from the string str2. The terminating null character is not included in the search. The function returns pointer to the matching character in str1. If str1 contains no characters from str2, the function returns 0.

Parameters
[in]str1Address of string 1.
[in]str2Address of string 2.
Returns
Address of matching character in str1.

◆ strrchr()

const char* strrchr ( const char *  ptr,
char  chr 
)

Function searches the string ptr for the last occurrence of character chr. The null character terminating ptr is not included in the search. The function returns pointer to the last chr found in ptr; if no matching character was found, function returns 0.

Parameters
[in]ptrAddress of string to check.
[in]chrCharacter to check for.
Returns
Address of last found character chr in string pointed to by ptr.

◆ strstr()

char* strstr ( const char *  str1,
const char *  str2 
)

Function locates the first occurrence of the string str2 in the string str1 (excluding the terminating null character). The function returns pointer to first occurrence of str2 in str1; if no string was found, function returns 0. If str2 is a null string, the function returns 0.

Parameters
[in]str1Address of string 1.
[in]str2Address of string 2.
Returns
Address of first str2 character occurence in str1.

◆ strtok()

char* strtok ( char *  str1,
char *  str2 
)

The strtok function returns a pointer to the first character of a token, or a null pointer if there is no token.

Parameters
[in]str1Address of string 1.
[in]str2Address of string 2.
Returns
Adress of adequate character.

◆ str_cut_chr()

void str_cut_chr ( char *  str,
char  num 
)

The str_cut_chr function removes all selected characters from string str, and returns it to the same str without those characters.

Parameters
[in]strAddress of string.
[in]numCharacter to cut.

◆ str_replace_chr()

void str_replace_chr ( char *  str,
char  chr_old,
char  chr_new 
)

The replace_chr function replaces all chr_old characters in string str with chr_new characters and returns it to the same str.

Parameters
[in]strAddress of string.
[in]chr_oldCharacter to be replaced.
[in]chr_newCharacter to replace with.

◆ str_cut_left()

void str_cut_left ( char *  str,
int  num 
)

The function str_cut_left crops string str to the left starting from position num.

Parameters
[in]strAddress of string.
[in]numStarting position.

◆ str_cut_right()

void str_cut_right ( char *  str,
int  num 
)

The function str_cut_right crops string str to the right starting from position num.

Parameters
[in]strAddress of string.
[in]numStarting position.

◆ str_split()

void str_split ( char *  str1,
char *  str2,
int  num 
)

The str_split function splits string str1 into two strings, str1 and str2, after the num-th character

Parameters
[in]str1Address of string 1.
[in]str2Address of string 2.
[in]numPosition to be split at.

◆ str_insert_chr()

void str_insert_chr ( char *  str,
char  chr,
int  num 
)

The str_insert_chr function adds selected character chr to string str at position num.

Parameters
[in]strAddress of string.
[in]chrCharacter to be added.
[in]numPosition to add at.