library - KimTaebin-ai/study_posts GitHub Wiki

isalpha

#include <ctype.h>haystack

int isalpha(int c);

checks for an alphabetic character; in the standard "C" locale, it is equivalent to (isup‐per(c) || islower(c)). In some locales, there may be additional characters for which isal‐pha() is true—letters which are neither uppercase nor lowercase.

isdigit

#include <ctype.h>

int isdigit(int c);

checks for a digit (0 through 9).

isalnum

#include <ctype.h>

int isalnum(int c);

checks for an alphanumeric character; it is equivalent to (isalpha(c) || isdigit(c)).

isascii

#include <ctype.h>

int isascii(int c);

checks whether c is a 7-bit unsigned char value that fits into the ASCII character set.

isprint

#include <ctype.h>

int isprint(int c);

checks for any printable character including space.

strlen

#include <string.h>

size_t strlen(const char *s);

DESCRIPTION

The strlen() function calculates the length of the string pointed to by s, excluding the terminating null byte ('\0').

RETURN VALUE

The strlen() function returns the number of bytes in the string pointed to by s.

memset

#include <string.h>

void *memset(void *s, int c, size_t n);

DESCRIPTION

The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c.

RETURN VALUE

The memset() function returns a pointer to the memory area s.

bzero

#include <strings.h>

void bzero(void *s, size_t n);

The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area.

The explicit_bzero() function performs the same task as bzero(). It differs from bzero() in that it guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is "unnecessary".

memcpy

#include <string.h>

void *memcpy(void *dest, const void *src, size_t n);

DESCRIPTION

The memcpy() function copies n bytes from memory area src to memory area dest. The memory areas must not overlap. Use memmove(3) if the memory areas do overlap.

RETURN VALUE

The memcpy() function returns a pointer to dest.

memmove

#include <string.h>

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

DESCRIPTION

The memmove() function copies n bytes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.

RETURN VALUE

The memmove() function returns a pointer to dest.

strlcpy

#include <string.h>

size_t strlcpy(char *dst, const char *src, size_t size);

DESCRIPTION

The strlcpy() and strlcat() functions copy and concatenate strings respectively. They are designed to be safer, more consistent, and less error prone replacements for strncpy(3) and strncat(3). Unlike those functions, strlcpy() and strlcat() take the full size of the buffer (not just the length) and guarantee to NUL-terminate the result (as long as size is larger than 0 or, in the case of strlcat(), as long as there is at least one byte free in dst). Note that a byte for the NUL should be included in size. Also note that strlcpy() and strlcat() only operate on true “C” strings. This means that for strlcpy() src must be NUL-terminated and for strlcat() both src and dst must be NUL-terminated.

The strlcpy() function copies up to size - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result.

The strlcat() function appends the NUL-terminated string src to the end of dst. It will append at most size -strlen(dst) - 1 bytes, NUL-terminating the result.

RETURN VALUES

The strlcpy() and strlcat() functions return the total length of the string they tried to create. For strlcpy() that means the length of src. For strlcat() that means the initial length of dst plus the length of src. While this may seem somewhat confusing, it was done to make truncation detection simple.

Note, however, that if strlcat() traverses size characters without finding a NUL, the length of the string is considered to be size and the destination string will not be NUL-terminated (since there was no space for the NUL). This keeps strlcat() from running off the end of a string. In practice this should not happen (as it means that either size is in‐correct or that dst is not a proper “C” string). The check exists to prevent potential security problems in incorrect code.

strlcat

#include <string.h>

size_t strlcat(char *dst, const char *src, size_t size);

toupper

#include <ctype.h>

int toupper(int c);

DESCRIPTION
These functions convert lowercase letters to uppercase, and vice versa.

If c is a lowercase letter, toupper() returns its uppercase equivalent, if an uppercase representation exists in the current locale. Otherwise, it returns c. The toupper_l() function performs the same task, but uses the locale re‐ferred to by the locale handle locale.

If c is an uppercase letter, tolower() returns its lowercase equivalent, if a lowercase representation exists in the current locale. Otherwise, it returns c. The tolower_l() function performs the same task, but uses the locale re‐ferred to by the locale handle locale. If c is neither an unsigned char value nor EOF, the behavior of these functions is undefined. The behavior of toupper_l() and tolower_l() is undefined if locale is the special locale object LC_GLOBAL_LOCALE (see duplocale(3)) or is not a valid locale object handle.

RETURN VALUE

The value returned is that of the converted letter, or c if the conversion was not possible.

tolower

#include <ctype.h>

int tolower(int c);

strchr

#include <string.h>
포인터가 가리키는 주소는 변경할  없지만,  주소에 저장된 데이터는 변경할  있다.
char *strchr(const char *s, int c);

DESCRIPTION

The strchr() function returns a pointer to the first occurrence of the character c in the string s.

RETURN VALUE

The strchr() and strrchr() functions return a pointer to the matched character or NULL if the character is not found.

The terminating null byte is considered part of the string, so that if c is specified as '\0', these functions return a pointer to the terminator.

strrchr

#include <string.h>

char *strrchr(const char *s, int c);

DESCRIPTION

The strrchr() function returns a pointer to the last occurrence of the character c in the string s.

RETURN VALUE

The strchr() and strrchr() functions return a pointer to the matched character or NULL if the character is not found.

The terminating null byte is considered part of the string, so that if c is specified as '\0', these functions return a pointer to the terminator.

strncmp

#include <string.h>

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

DESCRIPTION

The strcmp() function compares the two strings s1 and s2. The locale is not taken into account (for a locale-aware comparison, see strcoll(3)). The comparison is done using unsigned characters.

strcmp() returns an integer indicating the result of the comparison, as follows:

• 0, if the s1 and s2 are equal;

• a negative value if s1 is less than s2;

• a positive value if s1 is greater than s2.

The strncmp() function is similar, except it compares only the first (at most) n bytes of s1 and s2.

RETURN VALUE

The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2.

memchr

#include <string.h>

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

DESCRIPTION

The memchr() function scans the initial n bytes of the memory area pointed to by s for the first instance of c. Both c and the bytes of the memory area pointed to by s are interpreted as unsigned char.

The memrchr() function is like the memchr() function, except that it searches backward from the end of the n bytes pointed to by s instead of forward from the beginning.

The rawmemchr() function is similar to memchr(): it assumes (i.e., the programmer knows for certain) that an instance of c lies somewhere in the memory area starting at the location pointed to by s, and so performs an optimized search for c (i.e., no use of a count argument to limit the range of the search). If an instance of c is not found, the re‐sults are unpredictable. The following call is a fast means of locating a string's terminating null byte: char *p = rawmemchr(s, '\0');

RETURN VALUE The memchr() and memrchr() functions return a pointer to the matching byte or NULL if the character does not occur in the given memory area.

The rawmemchr() function returns a pointer to the matching byte, if one is found. If no matching byte is found, the result is unspecified.

memcmp

#include <string.h>

int memcmp(const void *s1, const void *s2, size_t n);

strnstr

#include <string.h>

char *strnstr(const char *big, const char *little, size_t len);

atoi

#include <stdlib.h>

int atoi(const char *nptr);

DESCRIPTION

The atoi() function converts the initial portion of the string pointed to by nptr to int. The behavior is the same as strtol(nptr, NULL, 10); except that atoi() does not detect errors.

The atol() and atoll() functions behave the same as atoi(), except that they convert the initial portion of the string to their return type of long or long long.

RETURN VALUE

The converted value or 0 on error.

calloc

#include <stdlib.h>

void *calloc(size_t nmemb, size_t size);

The calloc() function allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero. If nmemb or size is 0, then calloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). If the multiplication of nmemb and size would result in integer overflow, then calloc() returns an error. By contrast, an integer overflow would not be detected in the following call to mal‐ loc(), with the result that an incorrectly sized block of memory would be allocated:malloc(nmemb * size);

The malloc() and calloc() functions return a pointer to the allocated memory, which is suitably aligned for any built-in type. On error, these functions return NULL. NULL may also be returned by a successful call to malloc() with a size of zero, or by a successful call to cal‐ loc() with nmemb or size equal to zero.

strdup

#include <string.h>

char *strdup(const char *s);

The strdup() function returns a pointer to a new string which is a du‐plicate of the string s. Memory for the new string is obtained with malloc(3), and can be freed with free(3).

On success, the strdup() function returns a pointer to the duplicated string. It returns NULL if insufficient memory was available, with er‐r no set to indicate the cause of the error.

ft_substr

char *ft_substr(char const *s, unsigned int start, size_t len);

Description

Allocates (with malloc(3)) and returns a substring from the string ’s’. The substring begins at index ’start’ and is of maximum size ’len’.

Return value

The substring. NULL if the allocation fails.

ft_strjoin

char *ft_strjoin(char const *s1, char const *s2);

Description

Allocates (with malloc(3)) and returns a new string, which is the result of the concatenation of ’s1’ and ’s2’.

Return value

The new string. NULL if the allocation fails.

ft_strtrim

char *ft_strtrim(char const *s1, char const *set);

Description

Allocates (with malloc(3)) and returns a copy of ’s1’ with the characters specified in ’set’ removed from the beginning and the end of the string.

Return Value

The trimmed string. NULL if the allocation fails.

ft_split

char **ft_split(char const *s, char c);

Description

Allocates (with malloc(3)) and returns an array of strings obtained by splitting ’s’ using the character ’c’ as a delimiter. The array must end with a NULL pointer.

Return value

The array of new strings resulting from the split. NULL if the allocation fails.

ft_itoa

char *ft_itoa(int n);

Description

Allocates (with malloc(3)) and returns a string representing the integer received as an argument. Negative numbers must be handled.

Return value

The string representing the integer. NULL if the allocation fails.

ft_strmapi

char *ft_strmapi(char const *s, char (*f)(unsigned int, char));

Description

Applies the function f to each character of the string s, passing its index as the first argument and the character itself as the second. A new string is created (using malloc(3)) to collect the results from the successive applications of f.

Return value

The string created from the successive applications of ’f’. Returns NULL if the allocation fails.

ft_striteri

void ft_striteri(char *s, void (*f)(unsigned int, char*));

Description

Applies the function ’f’ on each character of the string passed as argument, passing its index as first argument. Each character is passed by address to ’f’ to be modified if necessary.

ft_putchar_fd

void ft_putchar_fd(char c, int fd);

Description

Outputs the character ’c’ to the given file descriptor.

ft_putstr_fd

void ft_putstr_fd(char *s, int fd);

Description

Outputs the string ’s’ to the given file descriptor.

ft_putendl_fd

void ft_putendl_fd(char *s, int fd);

Description Outputs the string ’s’ to the given file descriptor followed by a newline.

ft_putnbr_fd

void ft_putnbr_fd(int n, int fd);

Description

Outputs the integer ’n’ to the given file descriptor.

ft_lstnew

t_list *ft_lstnew(void *content);

Description Allocates (with malloc(3)) and returns a new node. The member variable ’content’ is initialized with the value of the parameter ’content’. The variable ’next’ is initialized to NULL.

Return value The new node

ft_lstadd_front

void ft_lstadd_front(t_list **lst, t_list *new);

Description Adds the node ’new’ at the beginning of the list.

ft_lstsize

int ft_lstsize(t_list *lst);

Description Counts the number of nodes in a list.

Return value The length of the list

ft_lstlast

t_list *ft_lstlast(t_list *lst);

Description Returns the last node of the list.

Return value Last node of the list

ft_lstadd_back

void ft_lstadd_back(t_list **lst, t_list *new);

Description Adds the node ’new’ at the end of the list.

ft_lstdelone

void ft_lstdelone(t_list *lst, void (*del)(void *));

Description Takes as a parameter a node and frees the memory of the node’s content using the function ’del’ given as a parameter and free the node. The memory of ’next’ must not be freed.

ft_lstclear

void ft_lstclear(t_list **lst, void (*del)(void *));

Description Deletes and frees the given node and every successor of that node, using the function ’del’ and free(3). Finally, the pointer to the list must be set to NULL.

ft_lstiter

void ft_lstiter(t_list *lst, void (*f)(void *));

Description Iterates the list ’lst’ and applies the function ’f’ on the content of each node.

ft_lstmap

t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));

Description Iterates the list ’lst’ and applies the function ’f’ on the content of each node. Creates a new list resulting of the successive applications of the function ’f’. The ’del’ function is used to delete the content of a node if needed.

Return value The new list. NULL if the allocation fails.

⚠️ **GitHub.com Fallback** ⚠️