StuBS
Loading...
Searching...
No Matches
String function

String functions as provided by string.h in the C standard library. More...

Functions

char * strchrnul (const char *s, int c)
 Find the first occurrence of a character in a string.
 
char * strchr (const char *s, int c)
 Find the first occurrence of a character in a string.
 
int strcmp (const char *s1, const char *s2)
 Compare two strings.
 
int strncmp (const char *s1, const char *s2, size_t n)
 Compare two strings.
 
size_t strlen (const char *s)
 Calculate the length of a string.
 
char * strcpy (char *dest, const char *src)
 Copy the contents of a string including the terminating null byte (\0)
 
char * strncpy (char *dest, const char *src, size_t n)
 Copy the contents of a string up to a maximum length or the terminating null byte (\0), whatever comes first.
 
void * memcpy (void *__restrict__ dest, void const *__restrict__ src, size_t size)
 Copy a memory area.
 
void * memmove (void *dest, void const *src, size_t size)
 Copy a memory area while the source may overlap with the destination.
 
void * memset (void *dest, int pattern, size_t size)
 Fill a memory area with a pattern.
 

Detailed Description

String functions as provided by string.h in the C standard library.

Function Documentation

◆ memcpy()

void * memcpy ( void *__restrict__ dest,
void const *__restrict__ src,
size_t size )

Copy a memory area.

Parameters
destdestination buffer
srcsource buffer
sizenumber of bytes to copy
Returns
pointer to destination
Note
The memory must not overlap!

◆ memmove()

void * memmove ( void * dest,
void const * src,
size_t size )

Copy a memory area while the source may overlap with the destination.

Parameters
destdestination buffer
srcsource buffer
sizenumber of bytes to copy
Returns
pointer to destination

◆ memset()

void * memset ( void * dest,
int pattern,
size_t size )

Fill a memory area with a pattern.

Parameters
destdestination buffer
patternsingle byte pattern
sizenumber of bytes to fill with pattern
Returns
pointer to destination

◆ strchr()

char * strchr ( const char * s,
int c )

Find the first occurrence of a character in a string.

Parameters
sstring to
ccharacter to find
Returns
Pointer to first occurrence of the character or to nullptr if not found

◆ strchrnul()

char * strchrnul ( const char * s,
int c )

Find the first occurrence of a character in a string.

Parameters
sstring to
ccharacter to find
Returns
Pointer to first occurrence of the character or to null byte at the end of the string if not found

◆ strcmp()

int strcmp ( const char * s1,
const char * s2 )

Compare two strings.

Parameters
s1first string
s2second string
Returns
an integer less than, equal to, or greater than zero if first string is found, respectively, to be less than, to match, or be greater than second string

◆ strcpy()

char * strcpy ( char * dest,
const char * src )

Copy the contents of a string including the terminating null byte (\0)

Parameters
destdestination string buffer
srcsource string buffer
Returns
a pointer to the destination string buffer
Note
Beware of buffer overruns!

◆ strlen()

size_t strlen ( const char * s)

Calculate the length of a string.

Parameters
spointer to a string
Returns
number of bytes in the string

◆ strncmp()

int strncmp ( const char * s1,
const char * s2,
size_t n )

Compare two strings.

Parameters
s1first string
s2second string
nnumber of bytes to compare
Returns
an integer less than, equal to, or greater than zero if the given number of bytes of the first string are found, respectively, to be less than, to match, or be greater than second string

◆ strncpy()

char * strncpy ( char * dest,
const char * src,
size_t n )

Copy the contents of a string up to a maximum length or the terminating null byte (\0), whatever comes first.

Parameters
destdestination string buffer
srcsource string buffer
nmaximum number of bytes to copy
Returns
a pointer to the destination string buffer
Note
If there is no null byte (\0) among the first n bytes, the destination will not be null-terminated!