Skip to content
AhmadNajiKamPublic

About

A clone of some libs functions written from scratch

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This activity has been created as part of the 42 curriculum by akamamji.

Libft - My First C Library

Description

Libft is the first project in the 42 Common Core curriculum. The goal is to build a custom C library (libft.a) that implements standard C library functions (libc) along with other useful utility functions.

This project is essential for understanding:

  • Low-level memory management (malloc, free).
  • Pointer arithmetic and manipulation.
  • How standard string and memory functions behave under the hood.
  • Data structures, specifically Linked Lists (Bonus part).

Once completed, this library will be reused in future school projects.

Instructions

1. Compilation

The project includes a Makefile that compiles the source files and generates the static library. Run the following commands in the terminal root of the repository:

  • Compile the library (Mandatory):

    make

    This generates libft.a.

  • Compile with Bonus functions (Linked Lists):

    make bonus

    This adds the list manipulation functions to the library.

  • Clean object files:

    make clean
  • Full clean (objects + library):

    make fclean
  • Recompile:

    make re

2. Usage

To use Libft in your C projects, you need to include the header file and link the static library during compilation.

Example:

  1. Include the header in your C file:
    #include "libft.h"
  2. Compile your file linking with libft.a:
    cc main.c -L. -lft -o my_program

Resources

Documentation & References

  • Man Pages: The primary reference for understanding the behavior of libc functions (e.g., man 3 memset, man 3 strlcat).
  • CPP Reference / GeeksforGeeks: Used for clarifying edge cases and return values for functions like memmove and strnstr.
  • GNU Make Manual: Referenced for creating the Makefile and understanding rules like .PHONY.

AI Usage

As part of the learning process, AI tools (Gemini) were used to assist with the following specific tasks:

  1. Debugging Memory Errors (Valgrind):
    • AI was used to interpret complex Valgrind errors, specifically "Invalid write of size 8" in ft_split. It helped identify an operator precedence issue in the malloc allocation size logic.
  2. Logic Verification & Edge Cases:
    • Verified the logic for handling INT_MIN in ft_itoa to prevent overflow.
    • Clarified the logic for memory overlap handling in ft_memmove (copying backwards vs forwards).
  3. Concept Explanation:
    • Used to understand the difference between unsigned char casting in memory functions and standard char pointers.

Note: All code implementation and final logic decisions were made by the student. AI was used strictly as a debugging assistant and for conceptual clarification.

Features

The library includes the following categories of functions:

  • Libc Functions: memset, bzero, memcpy, memmove, memchr, memcmp, strlen, strlcpy, strlcat, strchr, strrchr, strnstr, strncmp, atoi, isalpha, isdigit, isalnum, isascii, isprint, toupper, tolower, calloc, strdup.
  • Additional Functions: ft_substr, ft_strjoin, ft_strtrim, ft_split, ft_itoa, ft_strmapi, ft_striteri, ft_putchar_fd, ft_putstr_fd, ft_putendl_fd, ft_putnbr_fd.
  • Bonus (Linked Lists): ft_lstnew, ft_lstadd_front, ft_lstsize, ft_lstlast, ft_lstadd_back, ft_lstdelone, ft_lstclear, ft_lstiter, ft_lstmap.

About

A clone of some libs functions written from scratch

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages