Libft is a project aimed at creating your own C library—a collection of useful functions that you'll be able to use in future C programming projects. The goal is to recreate standard C library functions and add additional ones that will come in handy throughout your coding journey.
All function implementations are placed here, with each function in its own file. Naming conventions should follow the pattern of the function name, for example:
ft_strlen.c
ft_strdup.c
- etc.
The header file contains declarations for all your functions. It should:
- Include all necessary libraries (e.g.,
#include <unistd.h>
, etc.) - Declare all function prototypes
- Be included in every
.c
file using#include "libft.h"
The Makefile is responsible for compiling the library. It should:
- Compile all
.c
files into object files - Create the static library
libft.a
- Include rules for
clean
,fclean
, andre
ft_isalpha
- checks if the character is alphabeticft_isdigit
- checks if the character is a digit (0 through 9)ft_isalnum
- checks if the character is alphanumericft_isascii
- checks if the character is part of the ASCII setft_isprint
- checks if the character is printableft_toupper
- converts the character to uppercaseft_tolower
- converts the character to lowercase
ft_memset
- fills memory with a constant byteft_strlen
- calculates the length of a stringft_bzero
- zeroes out a byte stringft_memcpy
- copies memory from one area to anotherft_memmove
- safely copies memory even if regions overlapft_strlcpy
- copies a string up to a specified sizeft_strlcat
- concatenates two strings up to a specified sizeft_strchr
- locates a character in a stringft_strrchr
- locates a character in a string, searching from the endft_strncmp
- compares two stringsft_memchr
- scans memory for a characterft_memcmp
- compares two memory areasft_strnstr
- locates a substring within a stringft_strdup
- duplicates a string
ft_atoi
- converts a string to an integerft_calloc
- allocates memory and sets it to zero
ft_substr
- returns a substring from a stringft_strjoin
- concatenates two stringsft_strtrim
- trims specified characters from the beginning and end of a stringft_split
- splits a string using a character as a delimiterft_itoa
- converts an integer to a stringft_strmapi
- applies a function to each character of a stringft_striteri
- applies a function to each character of a string using the indexft_putchar_fd
- outputs a character to the given file descriptorft_putstr_fd
- outputs a string to the given file descriptorft_putendl_fd
- outputs a string followed by a newline to the given file descriptorft_putnbr_fd
- outputs a number to the given file descriptor
If you've finished the mandatory part, you can implement a set of linked list functions:
ft_lstnew
- creates a new list elementft_lstadd_front
- adds an element at the beginning of the listft_lstsize
- counts the number of elements in the listft_lstlast
- returns the last element in the listft_lstadd_back
- adds an element to the end of the listft_lstclear
- deletes and frees the listft_lstiter
- applies a function to each element of the listft_lstmap
- applies a function to each element of the list, creating a new list
Function | Description | Memory Usage | Cycles (Typical) |
---|---|---|---|
ft_memset |
Fill memory with constant byte | O(n) | n + 3 |
ft_bzero |
Zero out a byte string | O(n) | n + 2 |
ft_memcpy |
Copy memory area | O(n) | n + 4 |
ft_memmove |
Safe memory copy with overlap | O(n) | n + 6 |
Libft is the foundation for your future C projects. It equips you with a set of essential tools and is a key step in mastering C programming. Happy coding!