Skip to content

πŸš€ Libft implementation, the first 1337/42 project. A custom C library re-creating core functions β€” memory, strings, chars, and linked lists πŸ”—. Designed to master low-level programming, memory management, and build a strong foundation for future 42 projects. πŸ’ͺπŸ”₯

Notifications You must be signed in to change notification settings

Frontendab/42-Libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

67 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

42-Libft

Your very first own C library.

A foundational project at 42 School, aimed at re-coding essential C standard library functions and learning how to build your own reusable library.

Celebrating

πŸ“˜ Introduction

The Libft project is about creating your own C library that re-implements many of the functions you will use throughout your future projects. It helps you understand the inner workings of common C functions, memory handling, and linked lists β€” building a strong foundation for low-level programming.

Someone lost in C pointers πŸ˜΅β€πŸ’«

Someone lost in C pointers

libft/
β”œβ”€β”€ .github/workflows
β”‚           └── run-test.yaml
β”œβ”€β”€ Makefile
β”œβ”€β”€ includes/
β”‚   └── libft.h
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Mandatory/
β”‚   β”‚   β”œβ”€β”€ *.c
β”‚   └── Bonus/
β”‚       β”œβ”€β”€ *.c
└── README.md

🧾 Common Instructions

  • Your project must follow 42’s Norm (norminette).

  • Your functions must not crash (no segfaults, double frees, or memory leaks).

  • All dynamically allocated memory must be properly freed.

  • You must include a Makefile with at least the rules:

    NAME, all, clean, fclean, re
  • The bonus part should be compiled with:

    make bonus
  • You are encouraged to create and use test programs for your own validation.

When the norminette says OK βœ… πŸ˜‚

When the norminette says OK βœ…

🧱 Mandatory Part

Requirement Details
Library Name libft.a
Files to turn in *.c, libft.h, Makefile
Compiler cc
Flags -Wall -Wextra -Werror
No global variables βœ… Required
Create archive with ar (not libtool)

🧩 Part 1 – Libc Functions

Re-code the following C standard library functions (without using restrict):

  isalpha   isdigit   isalnum   isascii   isprint
  strlen    memset    bzero     memcpy    memmove
  strlcpy   strlcat   toupper   tolower   strchr
  strrchr   strncmp   memchr    memcmp    strnstr
  atoi

And using malloc:

  calloc    strdup

malloc never returns NULL… right? πŸ˜…

Coding Rage

🧰 Part 2 – Additional Functions

Functions that are not in libc or have modified behavior:

Function Description
ft_substr Returns a substring from a string.
ft_strjoin Concatenates two strings.
ft_strtrim Trims characters from the beginning and end of a string.
ft_split Splits a string using a delimiter.
ft_itoa Converts an integer to a string.
ft_strmapi Applies a function to each character of a string (creates a new string).
ft_striteri Applies a function to each character of a string (in-place).
ft_putchar_fd Outputs a character to a file descriptor.
ft_putstr_fd Outputs a string to a file descriptor.
ft_putendl_fd Outputs a string followed by a newline.
ft_putnbr_fd Outputs an integer to a file descriptor.

🧩 Bonus Part

Once you’ve completed the mandatory part, you can implement linked list functions.

🧱 Struct Definition

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

πŸ”— Bonus Functions

Function Description
ft_lstnew Creates a new list node.
ft_lstadd_front Adds a node at the beginning.
ft_lstsize Returns the number of nodes.
ft_lstlast Returns the last node.
ft_lstadd_back Adds a node at the end.
ft_lstdelone Frees a single node.
ft_lstclear Frees an entire list.
ft_lstiter Iterates over a list and applies a function.
ft_lstmap Creates a new list by applying a function to each node.

To compile with the bonus part:

make bonus

Linked list chaos πŸͺ’πŸ˜‚

Linked list chaos πŸͺ’πŸ˜‚)

πŸ§ͺ Compilation Examples

# Compile the library
make

# Compile the bonus functions
make bonus

# Clean object files
make clean

# Remove binaries and library
make fclean

# Recompile from scratch
make re

# Build and run test program
make test

Makefile says Done compiling πŸ˜πŸ‘

Makefile says Done compiling πŸ˜πŸ‘

🧰 Test the Norminette or Build via GitHub Actions

If you want to check your code’s Norminette or Build automatically through GitHub:

  1. Go to your repository on GitHub.
  2. Click on the "Actions" tab.
  3. Find the workflow named β€œCheck the Norminette or Build of the code”.
  4. Click β€œRun workflow”.
  5. In the dropdown, select the type β†’ Choose the type of test?.
  6. Click β€œRun workflow” again.

GitHub Actions will automatically test your code against the Norminette or Build rules and display the result in the Actions panel βœ….

Waiting for CI to pass ⏳🀞

Waiting for CI to pass ⏳🀞

🧠 Tips

  • Test your functions one by one before adding them to the library.
  • Keep helper (static) functions internal β€” don’t expose them in libft.h.
  • Check memory leaks.
  • Expand your Libft as you progress β€” it’s your foundation for future 42 projects.

🏁 Final Goal

By the end of this project, you will:

  • Understand how the C standard library works internally
  • Have a custom reusable C library for all future projects
  • Master memory management, string manipulation, and linked list operations

πŸ’¬ Author

Made with ❀️ as part of the 42 School Curriculum

β€œUnderstanding the foundation of C is the first step toward mastering programming.”

Thanks for reading πŸ™Œ

Thanks for reading πŸ™Œ

About

πŸš€ Libft implementation, the first 1337/42 project. A custom C library re-creating core functions β€” memory, strings, chars, and linked lists πŸ”—. Designed to master low-level programming, memory management, and build a strong foundation for future 42 projects. πŸ’ͺπŸ”₯

Topics

Resources

Stars

Watchers

Forks