Skip to content

enekomb/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Libft - 42 School Project

A complete implementation of the fundamental C library required for the 42 curriculum. This library includes recreated standard C functions, additional utility functions, and bonus linked list operations.

🎯 Project Overview

Libft is the first project at 42 School where students recreate essential C standard library functions and create additional utilities. This project serves as the foundation for many future 42 projects.

Key Requirements:

  • ✅ All functions follow Norminette (42's coding standard)
  • ✅ No forbidden functions (only malloc, free, and write where allowed)
  • ✅ Strict memory management (no memory leaks)
  • ✅ Compiled with -Wall -Wextra -Werror flags

📋 Function Reference

Part 1: Libc Functions (23 functions)

Standard C library functions reimplemented without using their original versions.

Function Description
Character Checks
ft_isalpha Check if character is alphabetic
ft_isdigit Check if character is a digit
ft_isalnum Check if character is alphanumeric
ft_isascii Check if character is ASCII
ft_isprint Check if character is printable
ft_toupper Convert character to uppercase
ft_tolower Convert character to lowercase
String Functions
ft_strlen Calculate string length
ft_strchr Locate character in string
ft_strrchr Locate character in string from end
ft_strncmp Compare strings up to n bytes
ft_strnstr Locate substring in string
ft_strlcpy Size-bounded string copy
ft_strlcat Size-bounded string concatenation
ft_strdup Duplicate string (malloc)
Memory Functions
ft_memset Fill memory with constant byte
ft_bzero Zero a byte string
ft_memcpy Copy memory area
ft_memmove Copy memory area (handles overlap)
ft_memchr Scan memory for character
ft_memcmp Compare memory areas
Conversion & Allocation
ft_atoi Convert string to integer
ft_calloc Allocate and zero memory

Part 2: Additional Functions (11 functions)

Custom utility functions that extend standard library functionality.

Function Description
String Manipulation
ft_substr Extract substring from string
ft_strjoin Concatenate two strings (malloc)
ft_strtrim Trim characters from string ends
ft_split Split string by delimiter into array
ft_itoa Convert integer to string
Function Application
ft_strmapi Apply function to each character with index
ft_striteri Iterate string and apply function
Output Functions
ft_putchar_fd Output character to file descriptor
ft_putstr_fd Output string to file descriptor
ft_putendl_fd Output string + newline to fd
ft_putnbr_fd Output integer to file descriptor

Bonus: Linked List Functions (9 functions)

Complete linked list manipulation toolkit using t_list structure.

Function Description
ft_lstnew Create new list element
ft_lstadd_front Add element at beginning of list
ft_lstadd_back Add element at end of list
ft_lstsize Count elements in list
ft_lstlast Get last element of list
ft_lstdelone Delete single list element
ft_lstclear Delete and free entire list
ft_lstiter Iterate list and apply function
ft_lstmap Iterate, apply function, create new list

t_list structure:

typedef struct s_list
{
    void            *content;
    struct s_list   *next;
}   t_list;

🔧 Compilation & Usage

Building the Library

# Clone the repository
git clone https://github.com/enekomb/libft.git
cd libft

# Compile mandatory functions only
make

# Compile with bonus functions
make bonus

# Clean object files
make clean

# Clean everything (objects + library)
make fclean

# Recompile from scratch
make re

This creates libft.a, a static library containing all the functions.

Using in Your Projects

1. Include the header in your C files:

#include "libft.h"

2. Compile your project with the library:

# Basic compilation
cc your_file.c -L. -lft -o your_program

# With flags
cc -Wall -Wextra -Werror your_file.c -L. -lft -o your_program

Example Usage:

#include "libft.h"
#include <stdio.h>

int main(void)
{
    char *str = ft_strdup("Hello, 42!");
    char **words = ft_split("one two three", ' ');
    t_list *list = ft_lstnew("Node 1");
    
    ft_putendl_fd(str, 1);
    
    // Remember to free allocated memory
    free(str);
    // ... free words array and list
    
    return (0);
}

🧪 Testing

While this repository focuses on implementation, you can test the functions using:

# Example with Tripouille's tester
git clone https://github.com/Tripouille/libftTester.git
cd libftTester
make

📁 Project Structure

LIBFT/
├── libft.h          # Header file with all prototypes and t_list struct
├── Makefile         # Compilation rules
├── ft_*.c           # 43 function implementation files
└── README.md        # This file

⚙️ Technical Details

  • Compiler: cc (clang/gcc)
  • Flags: -Wall -Wextra -Werror
  • Standard: C89/C90 compatible
  • Archive tool: ar rcs
  • Norminette: v3.x compliant

📖 Learning Outcomes

This project teaches:

  • 🔹 Deep understanding of C standard library internals
  • 🔹 Manual memory management and leak prevention
  • 🔹 Pointer manipulation and edge case handling
  • 🔹 Makefile creation and library archiving
  • 🔹 Data structures (linked lists)
  • 🔹 Strict coding standards (Norminette)

⚠️ Academic Integrity

This repository is shared for educational and portfolio purposes only.

For 42 Students:

  • 🚫 Do not copy this code for your own Libft project
  • ✅ Use it as a reference to understand concepts
  • ✅ Learn from the implementation approaches
  • ✅ Write your own original code

42's core values are learning through practice, peer collaboration, and genuine problem-solving.


👤 Author

Eneko Muñoz Bordona


📄 License

All rights reserved. This code is provided for educational purposes only.

If you're a 42 student, please respect the school's policies on code sharing and academic integrity.


Made with ❤️ at 42 Urduliz

About

C standard library reimplementation — 42 Urduliz

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Contributors