Skip to content

Yan-Carrel/Libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libft

This project has been created as part of the 42 curriculum by yaandria.

Description

This project is part of the 42 curriculum and focuses on recreating a custom C library. The goal is to reimplement essential standard C library functions in order to gain a deeper understanding of memory management, string manipulation, and low-level programming concepts.

Through this project, students learn how common libc functions work internally and develop rigorous coding practices following the 42 Norm.

Instructions

Compilation

To compile the library, run:

make

This will generate the libft.a static library.

Usage

To use the library in your project, include the header file:

#include "libft.h"

Then compile your project with libft.a :

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

Cleaning

To remove object files :

make clean

To remove object files and the library :

make fclean

To recompile everything from scratch :

make re

Resources

References

  • YouTube

    • Neso Academy – explanations of C programming concepts and standard library functions
    • Barry Brown – tutorials and practical demonstrations related to C and low-level programming
  • Documentation

Use of Artificial Intelligence

Artificial Intelligence tools were used as a complementary learning aid during the development of this project. AI was mainly used to:

  • Obtain alternative explanations when the information provided in man pages was difficult to understand
  • Clarify edge cases and expected behaviors of certain standard C library functions

Library Overview

The library created for this project, libft, is a custom implementation of several standard C library functions. It provides a collection of utility functions commonly used in C programming, allowing projects to rely on a personal, reusable, and well-understood codebase.

The library includes functions for:

  • Memory manipulation
  • String handling and analysis
  • Character checks and conversions
  • Linked list management

All functions are implemented in compliance with the 42 Norm and follow the behavior of their corresponding standard library equivalents whenever applicable.

Features and Function List

Memory manipulation

  • ft_memset
  • ft_bzero
  • ft_memcpy
  • ft_memmove
  • ft_memchr
  • ft_memcmp
  • ft_calloc

String manipulation

  • ft_strlen
  • ft_strlcpy
  • ft_strlcat
  • ft_strchr
  • ft_strrchr
  • ft_strncmp
  • ft_strnstr
  • ft_strdup
  • ft_substr
  • ft_strjoin
  • ft_strtrim
  • ft_split
  • ft_itoa
  • ft_strmapi
  • ft_striteri

Character checks and conversions

  • ft_isalpha
  • ft_isdigit
  • ft_isalnum
  • ft_isascii
  • ft_isprint
  • ft_toupper
  • ft_tolower

File descriptor output

  • ft_putchar_fd
  • ft_putstr_fd
  • ft_putendl_fd
  • ft_putnbr_fd

Linked list utilities

  • ft_lstnew
  • ft_lstadd_front
  • ft_lstadd_back
  • ft_lstsize
  • ft_lstlast
  • ft_lstdelone
  • ft_lstclear
  • ft_lstiter
  • ft_lstmap

Usage Examples

After compiling the library, include the header file in your source code:

Example 1: String manipulation

#include "libft.h"

int	main(void)
{
	char	*str;
	char	*ptr;

	str = "Hello, world!";
	ptr = ft_strrchr(str, 'o');
	if (ptr)
	{
		ft_putstr_fd("Found: ", 1);
		ft_putstr_fd(ptr, 1);
		ft_putchar_fd('\n', 1);
	}
	return (0);
}

Example 2 : Memory search

#include "libft.h"

int	main(void)
{
	char	data[5];
	void	*res;

	data[0] = 1;
	data[1] = 2;
	data[2] = 3;
	data[3] = 4;
	data[4] = 5;

	res = ft_memchr(data, 3, 5);
	if (res)
		ft_putstr_fd("Value found\n", 1);
	else
		ft_putstr_fd("Value not found\n", 1);
	return (0);
}

Compile with:

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

Technical Choices

  • The library is implemented in C and compiled as a static library (libft.a) to allow easy reuse across multiple projects.

  • Functions were written to closely match the behavior of their standard C library equivalents, following official documentation (man pages and libc references).

  • All memory allocations are carefully managed to avoid memory leaks and undefined behavior.

  • The project strictly follows the 42 Norm, including formatting rules, function length limits, and file organization.

  • No external libraries are used; only standard C headers are included when allowed by the project constraints.

Project Structure

The project is organized as follows:

libft/
├── ft_atoi.c
├── ft_bzero.c
├── ft_calloc.c
├── ft_isalnum.c
├── ft_isalpha.c
├── ft_isascii.c
├── ft_isdigit.c
├── ft_isprint.c
├── ft_itoa.c
├── ft_memchr.c
├── ft_memcmp.c
├── ft_memcpy.c
├── ft_memmove.c
├── ft_memset.c
├── ft_putchar_fd.c
├── ft_putstr_fd.c
├── ft_putendl_fd.c
├── ft_putnbr_fd.c
├── ft_split.c
├── ft_strchr.c
├── ft_strjoin.c
├── ft_strdup.c
├── ft_strtrim.c
├── ft_strlcat.c
├── ft_substr.c
├── ft_strmapi.c
├── ft_striteri.c
├── ft_strlcpy.c
├── ft_strlen.c
├── ft_strncmp.c
├── ft_strnstr.c
├── ft_strrchr.c
├── ft_tolower.c
├── ft_toupper.c
├── ft_lstnew.c
├── ft_lstadd_front.c
├── ft_lstadd_back.c
├── ft_lstsize.c
├── ft_lstlast.c
├── ft_lstdelone.c
├── ft_lstclear.c
├── ft_lstiter.c
├── ft_lstmap.c
├── libft.h
├── Makefile
└── README.md

Notes

  • includes/ contains all header files for the library
  • srcs/ contains the implementations of the functions
  • Makefile handles compilation (make, make clean, make fclean, make re)
  • README.md documents the project

About

*This project has been created as part of the 42 curriculum by yaandria.*

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors