Skip to content

Latest commit

 

History

History
197 lines (150 loc) · 6.43 KB

File metadata and controls

197 lines (150 loc) · 6.43 KB

Libft - 42 School Project

Build Status C License 42 School

A comprehensive C library implementation for 42 School curriculum

📋 Overview

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.

🚀 Features

Core Functions (42 Mandatory)

  • 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

Bonus Functions (Linked Lists)

  • List manipulation: lstnew, lstadd_front, lstadd_back, lstsize, lstlast
  • List operations: lstdelone, lstclear, lstiter, lstmap

📁 Project Structure

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

🛠️ Installation & Usage

Prerequisites

  • GCC compiler
  • Make build system
  • Standard C libraries

Building the Library

  1. Clone the repository:

    git clone https://github.com/your-username/libft42.git
    cd libft42
  2. Build the library:

    make
  3. Build with bonus functions:

    make bonus
  4. Clean build files:

    make clean
    make fclean  # Also removes the library
    make re      # Rebuild everything

Using in Your Projects

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./inc

🧪 Comprehensive Testing

Run the comprehensive test suite to verify all functions work correctly:

Linux/macOS:

# Run all tests with memory leak detection
./run_tests.sh

Manual execution:

# 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_main

The 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

📊 Function Index

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)

🎯 42 School Requirements

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

🔧 Technical Details

Memory Management

  • All functions handle edge cases and null pointers appropriately
  • Proper memory allocation and deallocation
  • Overflow protection in numeric conversions

Performance

  • Optimized string operations
  • Efficient memory copying algorithms
  • Minimal overhead implementations

Code Quality

  • Clean, readable code structure
  • Consistent coding style
  • Comprehensive function documentation

📚 Learning Outcomes

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

🤝 Contributing

While this is a personal 42 School project, suggestions and improvements are welcome:

  1. Fork the repository
  2. Create a feature branch
  3. Make your improvements
  4. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Miguel González Clayton


Built with ❤️ as part of the 42 School curriculum