Skip to content

Chrystian-Natanael/Libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 

Repository files navigation

Let's talk about: LIBFT 💬

libft_banner

Select a language:

libft         libft

About the project

libft

Libft is the first major project of school 42, where the goal is to build our first static library of functions, in C language.
Throughout the project, we dealt with several challenges, such as understanding the concept of memory and its addresses, and a lot of programming logic.

📂 Files of library

Here I'm going to list the functions of libft, explaining a bit about them and what to worry about when starting your project.
Clicking on the function will take you to my libft in the code of the respective function.



Mandatory part 1:

The Isalpha function takes a character (in ASCII code) and checks if it is an alphabetic character, and returns 0 if it is, and different from 0 if it is not.

The Isdigit function takes a character (in ASCII code) and checks if it is an digit character (0 - 9), and returns 0 if it is, and different from 0 if it is not.

Like the previous two functions, this one also takes an ASCII character and checks if it is an alphabetic character or a digit. returning 0 if it is, different from 0 if is not.

As you may have noticed from the pattern, this function checks if the character is between the ASCII character range (0 - 127), the return is also 0 if it is and different from 0 if is not.

The Isprint function takes a character (in ASCII code) and checks if it is a printable character, including spaces. It returns 0 if it is a printable character, and different from 0 if it is not.

This function searches for the last occurrence of a character in a string. It returns a pointer to the last occurrence of the character, or NULL if the character is not found in the string.

Strlen measures the length of a string. It returns the number of characters before the terminating null byte ('\0').

Strncmp compares up to n characters of two strings. It returns an integer less than, equal to, or greater than zero if the first n characters of s1 is found, respectively, to be less than, to match, or be greater than the first n characters of s2.

Memset fills the first n bytes of the memory area pointed to by s with the constant byte c. It returns a pointer to the memory area s.

Bzero sets the first n bytes of the area starting at s to zero.

This function scans the initial n bytes of the memory area pointed to by s for the first instance of c. It returns a pointer to the matching byte or NULL if the character does not occur in the given memory area.

Memcpy copies n bytes from memory area src to memory area dest. The memory areas must not overlap. It returns a pointer to dest.

Memcmp compares the first n bytes of the memory areas s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2.

Memmove copies n bytes from src to dest. The memory areas may overlap; it correctly handles overlapping areas.

This function locates the first occurrence of the null-terminated string needle in the string haystack, where not more than len characters are searched. Characters that appear after a '\0' character are not searched.

Strlcpy copies up to size -1 characters from the NUL-terminated string src to dst, NUL-terminating the result.

Strlcat 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.

The Toupper function converts a lower-case letter to the corresponding upper-case letter.

Conversely, the Tolower function converts an upper-case letter to the corresponding lower-case letter.

Strchr locates the first occurrence of c (converted to a char) in the string pointed to by s. The terminating null byte is considered part of the string; therefore if c is '\0', the functions locate the terminating '\0'.

For ft_calloc(), we are allowed to use the MALLOC() function. This function allocates memory, just like malloc, but with the difference of starting the spaces of the allocated memory with '\0'.

Mandatory part 2:

Creates a new substring from a given string s. It starts at index start and has a maximum size len. Returns the substring or NULL if memory allocation fails.

Joins two strings s1 and s2 into a new string. Returns the new string or NULL if memory allocation fails.

Trims the characters specified in set from the beginning and end of s1. Returns the trimmed string or NULL if allocation fails.

splits a string s using c as the delimiter. Returns an array of strings resulting from the split or NULL if allocation fails.

Converts an integer n into a string. Handles negative numbers. Returns the string or NULL if allocation fails.

Applies function f to each character of string s. The function f receives the character's index and character as arguments. Returns a new string created from successive applications of f or NULL if allocation fails.

Applies function f to each character of string s, with the character's index as the first argument. Modifies each character if necessary.

Outputs the character c to the file descriptor fd.

Outputs the string s to the file descriptor - fd.

Outputs the string s to the file descriptor - fd, followed by a newline.

Outputs the integer n to the file descriptor fd.

Bonus part:

Creates a new list node with content. Returns the new node or NULL if allocation fails.

Adds the node new at the beginning of the list lst.

Counts the number of nodes in a list lst. Returns the length of the list.

Returns the last node of the list lst.

Adds the node new at the end of the list lst.

Frees the memory of the node's lst content using del function, then frees the node. The next memory is not freed.

Deletes and frees the given node lst and every successor, using the function del. Sets the pointer to the list to NULL afterwards.

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

Iterates over the list lst, applies the function f on each node's content, and creates a new list from the results. Uses del to delete the content of a node if needed.