This project has been created as part of the 42 curriculum by adede.
This libft project is the first part of the 42 cursus and recreates a set of standard C library functions, as well as some additional utility functions. The goal is to understand C programming, memory management, string manipulation and simple linked list structuring.
This library serves as a collection of useful functions that can hopefully be reused in future projects.
This library includes:
- Character checks and conversions:
ft_isalpha,ft_isdigit,ft_toupper,ft_tolower, etc. - Memory functions:
ft_memset,ft_memcpy,ft_memmove,ft_calloc, etc. - String functions:
ft_strlen,ft_strlcpy,ft_strlcat,ft_strdup,ft_split, etc. - Linked list functions:
ft_lstnew,ft_lstadd_back,ft_lstlast,ft_lstclear,ft_lstmap, etc.
This library is written in C and compiled as a static library libft.a that can be included in other projects.
To compile the library, run:
makeThis will generate the libft.a static library.
To use libft in your projects, include the header:
#include "libft.h"and link the library during compilation:
gcc main.c -L. -lftTo clean object files:
make cleanTo clean everything, including the library:
make fcleanTo recompile:
make reThis libft library includes some standard C functions and additional utilities, categorized below:
ft_atoi— converts a string to an integerft_itoa— converts an integer to a string
ft_memset— fills memory with a constant byteft_memcpy— copies memory areaft_memmove— copies memory area safely with overlapft_memchr— locates a byte in memoryft_memcmp— compares two memory areasft_bzero— sets memory to zeroft_calloc— allocates memory and initializes it to zero
ft_isalpha— checks if character is alphabeticft_isdigit— checks if character is a digitft_isalnum— checks if character is alphanumericft_isascii— checks if character is an ASCII characterft_isprint— checks if character is printableft_toupper— converts character to uppercaseft_tolower— converts character to lowercase
ft_strlen— calculates string lengthft_strlcpy— copies a string safelyft_strlcat— concatenates strings safelyft_strchr— locates first occurrence of a character in stringft_strrchr— locates last occurrence of a character in stringft_strncmp— compares two strings up to n charactersft_strnstr— locates a substring in a stringft_strdup— duplicates a stringft_substr— extracts a substring from a stringft_strjoin— joins two stringsft_strtrim— trims characters from the beginning and end of a stringft_split— splits a string into an array of stringsft_strmapi— applies a function to each character of a string to create a new stringft_striteri— applies a function to each character of a string in-place
ft_putchar_fd— outputs a character to a file descriptorft_putstr_fd— outputs a string to a file descriptorft_putendl_fd— outputs a string followed by a newline to a file descriptorft_putnbr_fd— outputs an integer to a file descriptor
ft_lstnew— creates a new list elementft_lstsize— counts the number of elements in a listft_lstlast— returns the last element of the listft_lstadd_front— adds an element at the beginning of the listft_lstadd_back— adds an element at the end of the listft_lstdelone— deletes one element of the listft_lstclear— deletes and frees the entire listft_lstiter— applies a function to each element of the listft_lstmap— creates a new list by applying a function to each element of the original list
- Creating static library with
ar - ASCII reference
size_tandSIZE_MAX- File descriptors
- Makefile
- Markdown cheat sheet
AI tools were used to:
- Create unit tests and inform about edge cases.
- Provide explanations for complex C concepts.
- Educate about real world uses of the functions that this library implements.
No AI was used to generate the library code directly; all functions were personally implemented but assistively tested.