string.h

Overview

Related Modules:

UTILS

Description:

Declares commonly used functions for string operations.

You can use the functions provided in this file to perform the mathematical operations required during development. The operations include copying, searching for, locating, and appending a string, as well as comparing two strings. You must pay attention to memory management during function calls.

Since:

1.0

Version:

1.0

Summary

Macros

Macro Name and Value

Description

strdupa(x)   strcpy(alloca(strlen(x)+1),x)

Copies a string to a new position.

Functions

Function Name

Description

memcpy (void __restrict dest, const void restrict src, size_t n)

void  

Copies a string (overlapping not allowed).

memmove (void dest, const void src, size_t n)

void  

Copies a string (overlapping allowed).

memset (void s, int c, size_t n)

void  

Copies a character to the specified memory area.

memcmp (const void s1, const void s2, size_t n)

int 

Compares two memory areas.

memchr (const void s, int c, size_t n)

void  

Searches for a character in the specified memory area.

strcpy (char dest, const char src)

char  

Copies a string.

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

char  

Copies n characters of a string.

strcat (char dest, const char src)

char  

Appends a string to another one.

strncat (char dest, const char src, size_t n)

char  

Appends the first n bytes of a string to another one.

strcmp (const char s1, const char s2)

int 

Compares two strings by characters.

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

int 

Compares the first n characters of two strings.

strcoll (const char s1, const char s2)

int 

Compares two strings by character for the program’s current locale.

strcoll_l (const char s1, const char s2, locale_t locale)

int 

Compares two strings by character for the specified locale.

strxfrm (char dest, const char src, size_t n)

size_t 

Converts the first n characters of the source string pointed to by src based on the program’s current locale specified by LC_COLLATE, and places them in the destination string pointed to by dest.

strchr (const char s, int c)

char  

Locates the first occurrence of a character in a string.

strrchr (const char s, int c)

char  

Locates the last occurrence of a character in a string.

strcspn (const char s, const char reject)

size_t 

Obtains the length of the initial segment of a string that contains characters not in reject.

strspn (const char s, const char accept)

size_t 

Obtains the length of the initial segment of a string that contains characters in accept.

strpbrk (const char s, const char accept)

char  

Searches for any of a set of characters in a string.

strstr (const char haystack, const char needle)

char  

Searches for a needle string in its haystack string.

strtok (char str, const char delim)

char  

Separates a string into a series of tokens separated by a delimiter.

strlen (const char s)

size_t 

Calculates the length of a string.

strerror (int errnum)

char  

Obtains an error description string of the specified error code.

strtok_r (char str, const char delim, char **saveptr)

char  

Separates a string into a series of tokens separated by a delimiter, with the saveptr parameter specified.

strerror_l (int errnum, locale_t locale)

char  

Obtains an error description string of the specified error code for the specified locale.

strerror_r (int errnum, char buf, size_t buflen)

char  

Obtains an error description string of the specified error code.

stpcpy (char dest, const char src)

char  

Copies a string.

stpncpy (char dest, const char src, size_t n)

char  

Copies n characters of a string.

strnlen (const char s, size_t maxlen)

size_t 

Calculates the length of a string.

strdup (const char s)

char  

Copies a string to a new position.

strndup (const char s, size_t n)

char  

Copies n characters of a string to a new position.

strsignal (int sig)

char  

Returns a string describing the signal number.

memccpy (void restrict dest, const void __restrict src, int c, size_t n)

void  

Copies a memory area to another one.

strsep (char *stringp, const char delim)

char  

Separates a string into a series of tokens separated by a delimiter.

strlcat (char d, const char s, size_t n)

size_t 

Appends the first n bytes of a string to another one.

strlcpy (char d, const char s, size_t n)

size_t 

Copies a string.

strverscmp (const char s1, const char s2)

int 

Compares strings of two versions (string 1 and string 2) and returns the comparison result.

strcasestr (const char haystack, const char needle)

char  

Searches for a needle string in its haystack string and returns a pointer.

memmem (const void haystack, size_t haystacklen, const void needle, size_t needlelen)

void  

Searches for a needle string in its haystack string.

memrchr (const void s, int c, size_t n)

void  

Searches for a character in the specified memory area.

mempcpy (void dest, const void src, size_t n)

void  

Copies a string (overlapping not allowed).