Skip to content

BrenoLSR/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Libft

Because every great project starts with building your own tools


πŸ“– Table of Contents


πŸ“š About

Libft is the first project in the 42 School curriculum. The goal is to reimplement a set of standard C library functions (libc) from scratch, without using the originals, and to build additional utility functions that will serve as the foundation for every future 42 project.

By completing Libft, students gain a deep understanding of how fundamental C functions work under the hood β€” from memory manipulation to string parsing β€” all while following strict norms and writing clean, maintainable code.

The result is a static library (libft.a) that can be linked to any future project.


πŸ—‚οΈ Project Structure

libft/
β”‚
β”œβ”€β”€ libft.h               # All function prototypes and the t_list struct
β”œβ”€β”€ Makefile              # Build system β€” compiles into libft.a
β”‚
β”œβ”€β”€ ft_isalpha.c          # Character classification
β”œβ”€β”€ ft_isdigit.c
β”œβ”€β”€ ft_isalnum.c
β”œβ”€β”€ ft_isascii.c
β”œβ”€β”€ ft_isprint.c
β”œβ”€β”€ ft_toupper.c          # Character conversion
β”œβ”€β”€ ft_tolower.c
β”‚
β”œβ”€β”€ ft_strlen.c           # String functions
β”œβ”€β”€ ft_strchr.c
β”œβ”€β”€ ft_strrchr.c
β”œβ”€β”€ ft_strncmp.c
β”œβ”€β”€ ft_strnstr.c
β”œβ”€β”€ ft_strdup.c
β”œβ”€β”€ ft_strlcpy.c
β”œβ”€β”€ ft_strlcat.c
β”œβ”€β”€ ft_substr.c
β”œβ”€β”€ ft_strjoin.c
β”œβ”€β”€ ft_strtrim.c
β”œβ”€β”€ ft_split.c
β”œβ”€β”€ ft_strmapi.c
β”œβ”€β”€ ft_striteri.c
β”‚
β”œβ”€β”€ ft_memset.c           # Memory functions
β”œβ”€β”€ ft_bzero.c
β”œβ”€β”€ ft_memcpy.c
β”œβ”€β”€ ft_memmove.c
β”œβ”€β”€ ft_memchr.c
β”œβ”€β”€ ft_memcmp.c
β”œβ”€β”€ ft_calloc.c
β”‚
β”œβ”€β”€ ft_atoi.c             # Conversion functions
β”œβ”€β”€ ft_itoa.c
β”‚
β”œβ”€β”€ ft_putchar_fd.c       # File descriptor output
β”œβ”€β”€ ft_putstr_fd.c
β”œβ”€β”€ ft_putendl_fd.c
└── ft_putnbr_fd.c

πŸ“‹ Function Reference

πŸ”€ Character Classification

Function Prototype Description
ft_isalpha int ft_isalpha(int c) Returns non-zero if c is alphabetic
ft_isdigit int ft_isdigit(int c) Returns non-zero if c is a decimal digit
ft_isalnum int ft_isalnum(int c) Returns non-zero if c is alphanumeric
ft_isascii int ft_isascii(int c) Returns non-zero if c is a valid ASCII character (0–127)
ft_isprint int ft_isprint(int c) Returns non-zero if c is a printable character
ft_toupper int ft_toupper(int c) Converts c to uppercase if it is lowercase
ft_tolower int ft_tolower(int c) Converts c to lowercase if it is uppercase

πŸ”‘ String Functions

Function Prototype Description
ft_strlen size_t ft_strlen(const char *s) Returns the length of string s
ft_strchr char *ft_strchr(const char *s, int c) Locates first occurrence of c in s
ft_strrchr char *ft_strrchr(const char *s, int c) Locates last occurrence of c in s
ft_strncmp int ft_strncmp(const char *s1, const char *s2, size_t n) Compares up to n bytes of s1 and s2
ft_strnstr char *ft_strnstr(const char *haystack, const char *needle, size_t len) Locates needle in haystack within len bytes
ft_strdup char *ft_strdup(const char *s) Returns a newly allocated copy of s
ft_strlcpy size_t ft_strlcpy(char *dst, const char *src, size_t size) Size-bounded string copy
ft_strlcat size_t ft_strlcat(char *dst, const char *src, size_t size) Size-bounded string concatenation
ft_substr char *ft_substr(const char *s, unsigned int start, size_t len) Returns a substring of s starting at start with max length len
ft_strjoin char *ft_strjoin(const char *s1, const char *s2) Returns a new string that is the concatenation of s1 and s2
ft_strtrim char *ft_strtrim(const char *s1, const char *set) Trims characters in set from the beginning and end of s1
ft_split char **ft_split(const char *s, char c) Splits s by delimiter c, returning a NULL-terminated array of strings
ft_strmapi char *ft_strmapi(const char *s, char (*f)(unsigned int, char)) Applies function f to each character of s, returning a new string
ft_striteri void ft_striteri(char *s, void (*f)(unsigned int, char *)) Applies function f to each character of s in place

🧠 Memory Functions

Function Prototype Description
ft_memset void *ft_memset(void *b, int c, size_t len) Fills len bytes of b with value c
ft_bzero void ft_bzero(void *s, size_t n) Zeroes n bytes of s
ft_memcpy void *ft_memcpy(void *dst, const void *src, size_t n) Copies n bytes from src to dst (no overlap)
ft_memmove void *ft_memmove(void *dst, const void *src, size_t len) Copies len bytes from src to dst (handles overlap)
ft_memchr void *ft_memchr(const void *s, int c, size_t n) Searches first n bytes of s for byte c
ft_memcmp int ft_memcmp(const void *s1, const void *s2, size_t n) Compares first n bytes of s1 and s2
ft_calloc void *ft_calloc(size_t count, size_t size) Allocates count * size bytes, zero-initialized

πŸ” Conversion Functions

Function Prototype Description
ft_atoi int ft_atoi(const char *str) Converts a string to its integer representation
ft_itoa char *ft_itoa(int n) Converts an integer to its string representation

πŸ–¨οΈ File Descriptor Output

Function Prototype Description
ft_putchar_fd void ft_putchar_fd(char c, int fd) Outputs character c to file descriptor fd
ft_putstr_fd void ft_putstr_fd(char *s, int fd) Outputs string s to file descriptor fd
ft_putendl_fd void ft_putendl_fd(char *s, int fd) Outputs string s followed by \n to file descriptor fd
ft_putnbr_fd void ft_putnbr_fd(int n, int fd) Outputs integer n to file descriptor fd

πŸ› οΈ Additional Utilities

These functions go beyond the standard libc reimplementations and are designed to be reused across future 42 projects.

Function Prototype Description
ft_substr char *ft_substr(...) Extract a substring from a string
ft_strjoin char *ft_strjoin(...) Concatenate two strings into a new one
ft_strtrim char *ft_strtrim(...) Trim a set of characters from both ends of a string
ft_split char **ft_split(...) Split a string into an array by a delimiter
ft_itoa char *ft_itoa(...) Convert an integer to a string
ft_strmapi char *ft_strmapi(...) Apply a function to each character, building a new string
ft_striteri void ft_striteri(...) Apply a function to each character in-place

βš™οΈ Installation & Compilation

Prerequisites

  • GCC or Clang
  • GNU Make
  • Linux or macOS

Clone & Build

git clone https://github.com/BrenoLSR/libft.git
cd libft
make

This generates the static library file libft.a in the root directory.


πŸ”— Usage

To use libft in another project, copy or link libft.a and libft.h, then compile with:

gcc main.c -L. -lft -o my_program

Or simply include it directly in your project's Makefile:

LIBFT_DIR = path/to/libft
LIBFT     = $(LIBFT_DIR)/libft.a

$(LIBFT):
	make -C $(LIBFT_DIR)

Then include the header in your source files:

#include "libft.h"

πŸ› οΈ Makefile Targets

Target Description
make / make all Compiles all .c files and generates libft.a
make clean Removes all .o object files
make fclean Removes .o files and libft.a
make re Full recompile from scratch (fclean + all)

πŸ‘€ Author

Breno LSR 42 SΓ£o Paulo

GitHub 42


"To understand what you use, build it yourself first."

About

Implementation of the Libft library developed within the 42 curriculum. It includes reimplemented libc functions in C, as well as additional utilities.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors