Skip to content

otmansabir/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libft

Personal C standard library implementation for the 42 curriculum. This project re-implements a subset of the C standard library functions and provides additional utilities frequently used in later projects.

Repository: https://github.com/otmansabir/libft

Features

  • Re-implementations of common libc functions
  • Safe string and memory utilities
  • Character checks and conversions
  • I/O helpers that write to file descriptors
  • Optional “bonus” linked list API (t_list)
  • Static library output: libft.a

Getting Started

Requirements

  • A POSIX-compatible environment (Linux/macOS)
  • make
  • gcc or clang

Build

  • Build the mandatory part:
    • make
  • Build with bonus (linked list) part:
    • make bonus
  • Clean object files:
    • make clean
  • Remove objects and the library:
    • make fclean
  • Full rebuild:
    • make re

This produces libft.a at the project root.

Usage

Include the project header and link against the built library:

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

int main(void)
{
    const char *s = "Hello 42 Network";
    char **parts = ft_split(s, ' ');
    for (size_t i = 0; parts && parts[i]; ++i) {
        printf("[%s]\n", parts[i]);
        free(parts[i]);
    }
    free(parts);

    printf("len: %zu\n", ft_strlen("libft"));

    int n = ft_atoi("   -42");
    char *as = ft_itoa(n);
    printf("atoi: %d itoa: %s\n", n, as);
    free(as);

    return 0;
}

Compile and link:

# From the repository root after running `make`
gcc -Wall -Wextra -Werror -I. main.c -L. -lft -o demo
./demo

If your project has a different include layout, adjust -I accordingly.

API Overview

Below is the typical scope of a 42 libft. Exact availability depends on the implementation in this repository.

Character checks and conversions

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

Memory

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

Strings

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

Conversions and I/O

  • ft_atoi
  • ft_putchar_fd, ft_putstr_fd, ft_putendl_fd, ft_putnbr_fd

Bonus (Linked List)

If the bonus part is included, a singly linked list API with:

  • t_list node structure
  • ft_lstnew, ft_lstadd_front, ft_lstsize, ft_lstlast
  • ft_lstadd_back, ft_lstdelone, ft_lstclear
  • ft_lstiter, ft_lstmap

Project Structure

A common structure for libft:

  • libft.h — public header
  • Makefile — build rules producing libft.a
  • *.c — function implementations
  • (Optional) bonus/*.c — linked list functions

Your repository may group files differently, but the library target remains libft.a.

Testing

You can write your own small test programs (like main.c above) or use community testers. Popular options:

  • alelievr/libft-unit-test
  • jtoty/Libftest
  • 42Paris/42FileChecker
  • y3ll0w42/libft-war-machine

Note: These external testers may have their own expectations; ensure your function behavior matches the 42 subject.

Norms and Notes

  • Code adheres to the 42 Norm where applicable.
  • All allocations should be paired with proper free calls by the caller when ownership is transferred (e.g., ft_split, ft_itoa, ft_strdup, etc.).
  • Functions are designed to be compatible with later 42 projects.

License

No license specified in the repository. If you plan to reuse or distribute, consider adding a LICENSE file.

Author

About

my own library in c

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published