Libft is a custom C library that implements essential functions found in the standard C library, as well as additional utility functions useful for other C projects. This project is part of the 42 School curriculum and introduces the concepts of creating a static library, memory management, and adhering to strict coding standards.
- Project Overview
- Common Instructions
- Part 1 - Libc Functions
- Part 2 - Additional Functions
- Bonus Part - Linked List Functions
Program name: libft.a
Files: Makefile
, libft.h
, ft_*.c
Makefile Rules: NAME
, all
, clean
, fclean
, re
, bonus
Objective: Write a collection of functions for a C library that will be useful across multiple projects.
- Language: The project must be written in C and adhere to the 42 School Norm.
- Memory Management: All allocated memory on the heap must be properly freed; no memory leaks are allowed.
- Makefile Requirements: The Makefile must compile with
-Wall
,-Wextra
, and-Werror
flags and should contain the specified rules.libtool
is not allowed; usear
to createlibft.a
.
- all: Compiles the library
- clean: Removes object files
- fclean: Removes object files and the library
- re: Recompiles everything from scratch
- bonus: Compiles additional functions in separate
_bonus
files
This section involves recreating several functions from the standard C library. Each function has the same behavior as the original, but the name is prefixed with ft_
(e.g., ft_strlen
for strlen
). These functions do not use external library calls unless stated otherwise.
- Character Checks:
ft_isalpha
,ft_isdigit
,ft_isalnum
,ft_isascii
,ft_isprint
- String Manipulation:
ft_strlen
,ft_strlcpy
,ft_strlcat
,ft_strchr
,ft_strrchr
,ft_strncmp
,ft_strnstr
- Memory Manipulation:
ft_memset
,ft_bzero
,ft_memcpy
,ft_memmove
,ft_memchr
,ft_memcmp
- Character Conversion:
ft_toupper
,ft_tolower
- String to Integer:
ft_atoi
- Memory Allocation:
ft_calloc
,ft_strdup
The following functions provide additional functionality not directly included in the C library. They are useful for string manipulation, memory allocation, and other utilities.
-
String Manipulation and Memory Allocation:
ft_substr
: Creates a substring from a given stringft_strjoin
: Concatenates two strings into a new stringft_strtrim
: Trims specified characters from the beginning and end of a stringft_split
: Splits a string into an array based on a delimiterft_itoa
: Converts an integer to a stringft_strmapi
: Creates a new string by applying a function to each characterft_striteri
: Applies a function to each character of a string by reference
-
File Descriptor Functions:
ft_putchar_fd
: Writes a character to a given file descriptorft_putstr_fd
: Writes a string to a given file descriptorft_putendl_fd
: Writes a string followed by a newline to a given file descriptorft_putnbr_fd
: Writes an integer to a given file descriptor
If completed, the bonus section introduces functions to work with linked lists. Use the following structure for each node:
typedef struct s_list {
void *content;
struct s_list *next;
} t_list;