A comprehensive C library implementation for 42 School curriculum
This project is my implementation of the Libft library as part of the 42 School curriculum. Libft is a fundamental project that involves recreating essential C standard library functions, plus some additional utility functions that are commonly used in C programming.
- String manipulation:
strlen,strchr,strrchr,strncmp,strnstr,strlcpy,strlcat - Memory management:
memset,memcpy,memmove,memchr,memcmp,bzero,calloc - Character classification:
isalpha,isdigit,isalnum,isascii,isprint,toupper,tolower - String conversion:
atoi,itoa - File I/O utilities:
putchar_fd,putstr_fd,putendl_fd,putnbr_fd - Advanced string operations:
substr,strjoin,strtrim,split,strmapi,striteri
- List manipulation:
lstnew,lstadd_front,lstadd_back,lstsize,lstlast - List operations:
lstdelone,lstclear,lstiter,lstmap
libft42/
βββ inc/
β βββ libft.h # Header file with all function declarations
βββ src/
β βββ ft_*.c # Implementation files (43 functions total)
β βββ ft_lst*.c # Bonus linked list functions
βββ Makefile # Build configuration
βββ README.md # This file
βββ en.subject.pdf # Original project specification
- GCC compiler
- Make build system
- Standard C libraries
-
Clone the repository:
git clone https://github.com/your-username/libft42.git cd libft42 -
Build the library:
make
-
Build with bonus functions:
make bonus
-
Clean build files:
make clean make fclean # Also removes the library make re # Rebuild everything
Include the header and link against the library:
#include "libft.h"
int main(void)
{
char *str = "Hello, World!";
size_t len = ft_strlen(str); // Custom strlen function
ft_putstr_fd("Length: ", 1);
ft_putnbr_fd(len, 1);
ft_putstr_fd("\n", 1);
return (0);
}Compile with:
gcc your_program.c -L. -lft -I./incRun the comprehensive test suite to verify all functions work correctly:
# Run all tests with memory leak detection
./run_tests.sh# Compile and run tests
make bonus
gcc -Wall -Wextra -Werror -o test_main test_main.c -L. -lft -I./inc
./test_main
# Check for memory leaks
valgrind --leak-check=full --show-leak-kinds=all ./test_mainThe comprehensive test (test_main.c) validates:
- β All 42 functions work correctly
- β No memory leaks (verified with Valgrind)
- β Edge cases handled properly
- β Ready for 42 School evaluation
| Category | Functions |
|---|---|
| String Basics | strlen, strchr, strrchr, strncmp, strnstr |
| Memory | memset, memcpy, memmove, memchr, memcmp, bzero, calloc |
| Character | isalpha, isdigit, isalnum, isascii, isprint, toupper, tolower |
| String Copy | strlcpy, strlcat |
| Conversion | atoi, itoa |
| File I/O | putchar_fd, putstr_fd, putendl_fd, putnbr_fd |
| Advanced String | substr, strjoin, strtrim, split, strmapi, striteri |
| Linked Lists | lstnew, lstadd_front, lstadd_back, lstsize, lstlast, lstdelone, lstclear, lstiter, lstmap |
Total: 42 functions (24 mandatory + 9 bonus + 9 additional)
This implementation follows the strict 42 School coding standards:
- β No memory leaks
- β Proper error handling
- β Norminette compliance
- β Forbidden functions not used
- β All mandatory functions implemented
- β All bonus functions implemented
- All functions handle edge cases and null pointers appropriately
- Proper memory allocation and deallocation
- Overflow protection in numeric conversions
- Optimized string operations
- Efficient memory copying algorithms
- Minimal overhead implementations
- Clean, readable code structure
- Consistent coding style
- Comprehensive function documentation
Through this project, I gained expertise in:
- C programming fundamentals
- Memory management and pointers
- String manipulation techniques
- Data structures (linked lists)
- Makefile and build systems
- Code organization and documentation
While this is a personal 42 School project, suggestions and improvements are welcome:
- Fork the repository
- Create a feature branch
- Make your improvements
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Miguel GonzΓ‘lez Clayton
- GitHub: @migclay12
- 42 School: miggonza
Built with β€οΈ as part of the 42 School curriculum