Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by <your_login>.

libft

Description

libft is a custom C library built from scratch as part of the 42 curriculum. The goal is to reimplement a selection of standard C library functions (from <string.h>, <ctype.h>, <stdlib.h>, etc.) as well as a set of additional utility functions that are not part of the standard libc but are commonly useful in C programs. The library also includes a complete set of singly linked list manipulation functions.

Once compiled, the library is packaged as a static archive (libft.a) that can be linked into any future 42 project, making it a foundational tool for the entire curriculum.

Library Overview

The library is organized into three parts:

Part 1 — Libc reimplementations (ft_ prefix): exact re-creations of standard functions, including character classification (ft_isalpha, ft_isdigit, ft_isalnum, ft_isascii, ft_isprint), string functions (ft_strlen, ft_strchr, ft_strrchr, ft_strncmp, ft_strnstr, ft_strlcpy, ft_strlcat, ft_strdup), memory functions (ft_memset, ft_bzero, ft_memcpy, ft_memmove, ft_memchr, ft_memcmp, ft_calloc), and conversion functions (ft_toupper, ft_tolower, ft_atoi).

Part 2 — Additional functions: utility functions not found in the standard libc, including ft_substr (extract a substring), ft_strjoin (concatenate two strings into a new one), ft_strtrim (strip characters from both ends of a string), ft_split (split a string by a delimiter into a NULL-terminated array), ft_itoa (convert an integer to a string), ft_strmapi (apply a function to each character of a string, producing a new string), ft_striteri (apply a function to each character of a string in-place), and four output functions writing to a file descriptor: ft_putchar_fd, ft_putstr_fd, ft_putendl_fd, ft_putnbr_fd.

Part 3 — Linked list functions: a full suite of functions to manipulate singly linked lists using the t_list structure (content + next), including ft_lstnew, ft_lstadd_front, ft_lstsize, ft_lstlast, ft_lstadd_back, ft_lstdelone, ft_lstclear, ft_lstiter, and ft_lstmap.

Instructions

Compilation

The Makefile compiles all source files and produces libft.a at the root of the repository.

# Build the library
make

# Clean object files
make clean

# Remove object files and the library
make fclean

# Rebuild from scratch
make re

Linking with your project

Once libft.a is built, you can link it into any C program:

cc -Wall -Wextra -Werror main.c -L. -lft -o my_program

Or simply include the .a file directly:

cc -Wall -Wextra -Werror main.c libft.a -o my_program

Files

File Role
libft.h Header — all prototypes and the t_list struct definition
ft_*.c One source file per function
Makefile Build rules: all, clean, fclean, re

All files are placed at the root of the repository. The library is built using ar (not libtool).

Usage Example

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

int main(void)
{
    char    *joined;
    char    **words;
    int     i;

    // String utilities
    joined = ft_strjoin("Hello, ", "world!");
    ft_putendl_fd(joined, 1);
    free(joined);

    // Split a string
    words = ft_split("one:two:three", ':');
    i = 0;
    while (words[i])
    {
        ft_putendl_fd(words[i], 1);
        free(words[i++]);
    }
    free(words);

    // Integer to string
    char *num = ft_itoa(-42);
    ft_putendl_fd(num, 1);
    free(num);

    return (0);
}

Resources

AI Usage

AI was not used to write or generate any code for this project. The 42 curriculum guidelines for this foundational phase require students to reason through and implement solutions independently in order to build genuine problem-solving skills.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages