Skip to content

migclay12/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors