A comprehensive C library containing reimplementations of standard C library functions, plus additional utility functions for string manipulation, memory management, linked lists, and formatted output.
- About
- Features
- Installation
- Usage
- Project Structure
- Testing
- Performance
- Function Categories
- Compilation Flags
- Forbidden Functions
- Key Features
- Contributing
- License
- Author
libft is a custom C library developed as part of the 42 School curriculum. It provides essential functions for C programming, including:
- Standard C library function reimplementations
- Additional utility functions for string and memory operations
- Linked list manipulation functions
- Custom
printfimplementation with file descriptor support get_next_linefunction for reading files line by line
- Character checks:
ft_isalpha,ft_isdigit,ft_isalnum,ft_isascii,ft_isprint - String functions:
ft_strlen,ft_strchr,ft_strrchr,ft_strncmp,ft_strnstr - Memory functions:
ft_memset,ft_memcpy,ft_memmove,ft_memchr,ft_memcmp - String copying:
ft_strlcpy,ft_strlcat - Character conversion:
ft_toupper,ft_tolower - String to integer:
ft_atoi,ft_atol - Memory allocation:
ft_calloc,ft_bzero - String duplication:
ft_strdup
- String manipulation:
ft_substr,ft_strjoin,ft_strtrim,ft_split - Number to string:
ft_itoa,ft_itoa_base - String iteration:
ft_strmapi,ft_striteri - File descriptor output:
ft_putchar_fd,ft_putstr_fd,ft_putendl_fd,ft_putnbr_fd
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;- List operations:
ft_lstnew,ft_lstadd_front,ft_lstadd_back - List utilities:
ft_lstsize,ft_lstlast - List manipulation:
ft_lstdelone,ft_lstclear,ft_lstiter,ft_lstmap
Custom ft_printf function with support for:
- Format specifiers:
%c,%s,%d,%i,%u,%x,%X,%p,%% - Flags:
-,0,#,,+ - Width and precision:
*,. - File descriptor version:
ft_printf_fd
get_next_line function for reading files line by line with configurable buffer size.
- GCC or any C compiler
- Make
# Clone the repository
git clone https://github.com/yourusername/libft.git
cd libft
# Compile the library
make
# Clean object files
make clean
# Clean everything
make fclean
# Recompile
make re#include "libft.h"gcc -Wall -Wextra -Werror your_file.c -L. -lft#include "libft.h"
int main(void)
{
// String functions
char *str = ft_strdup("Hello, World!");
char **split = ft_split(str, ' ');
// Linked list
t_list *list = ft_lstnew("First");
ft_lstadd_back(&list, ft_lstnew("Second"));
// Printf
ft_printf("Number: %d, String: %s\n", 42, "libft");
// Memory cleanup
free(str);
// ... free split array and list
return (0);
}libft/
βββ Makefile # Build configuration
βββ libft.h # Main header file
βββ ft_printf.h # Printf header file
βββ get_next_line.h # Get next line header file
βββ README.md # This file
βββ .gitignore # Git ignore rules
βββ ft_*.c # Function implementations
βββ obj/ # Object files (created during build)
The library has been thoroughly tested with:
- Custom test suites
- 42 School testers
- Memory leak detection with Valgrind
- Edge cases and error handling
- Optimized algorithms for memory operations
- Efficient string manipulation
- Minimal memory footprint
- No unnecessary function calls
| Category | Functions | Description |
|---|---|---|
| Character Tests | 5 functions | Check character properties |
| String Operations | 15+ functions | String manipulation and analysis |
| Memory Management | 8 functions | Memory allocation and manipulation |
| Linked Lists | 9 functions | Dynamic data structure operations |
| File I/O | 6 functions | File descriptor operations |
| Printf | 15+ functions | Formatted output implementation |
| Utilities | 10+ functions | Helper and conversion functions |
The library is compiled with strict flags to ensure code quality:
-Wall -Wextra -WerrorThis implementation doesn't use any external libraries except for:
malloc,free(memory management)write(system call)- Standard library headers for type definitions
- Memory Safe: All functions handle edge cases and prevent buffer overflows
- Norm Compliant: Follows 42 School coding standards
- Well Documented: Each function includes comprehensive documentation
- Modular Design: Functions can be used independently
- Performance Optimized: Efficient algorithms and minimal overhead
This is an educational project for 42 School. While not accepting external contributions, feel free to:
- Report bugs
- Suggest improvements
- Use as a reference for your own implementation
This project is part of the 42 School curriculum and follows their academic guidelines.
joamiran - 42 Lisboa Student
This library represents a comprehensive foundation for C programming, providing essential tools for memory management, string manipulation, and formatted output while maintaining high code quality standards.