Skip to content
/ libft Public

A comprehensive C library that provides a collection of custom-made functions.

Notifications You must be signed in to change notification settings

arommers/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CODAM

Libft

The libft project is a custom C library, providing a comprehensive set of standard C functions for tasks like string manipulation, memory allocation, and linked list handling.

All the functions we've created in this repo are linked and packaged up into a static library called libft.a.
Think of it as a handy toolbox for essential C utilities. We can link this library to our other projects and tap into this treasure trove of helpful functions. Libft is a solid foundation to build upon, for many of our future projects.

Our own trusty sidekick for coding in C!


Key Concepts:

  • Algorithms and data structures
  • String handling functions (strlen, strcpy, strcat, etc.)
  • Memory management functions (malloc, free, memset, etc.)
  • Character manipulation functions (isalpha, isdigit, tolower, etc.)
  • Additional utility functions for various common tasks (ft_split, str_trim, itoa, etc)
  • Linked list operations for dynamic data structures
  • Makefile construction

Usage*:

  • Clone the repository:

    Either use the following command in your terminal: git clone https://github.com/arommers/libft.git
    Or Click the green "Code" button in the upper right corner to download the zip file and then unzip it.

  • Compile the library using the cmd   make

  • Include Header Files:

    In your C source file (.c), include the necessary header files from libft. This allows your code to access the function declarations.
    For example, if you want to use ft_strlen, include libft.h at the beginning of your file: #include libft

  • Link the Library:

    When compiling your program, you need to tell the compiler to include the libft library.
    This is done using the -L flag (to specify the library directory) and -l flag (to specify the library name).
    Assuming your libft.a is located in a directory named lib within your project directory, you would compile like this:

    gcc -o <your_program> <your_program.c> -L./lib -lft

    Here, <your_program> is the name of your executable, <your_program.c> is your source file, and -L./lib specifies the library directory as ./lib, while -lft specifies that it should link with libft.a.

  • Compile and Run:

    Now, compile your program as usual. The compiler will use the functions from libft.a while building your program. When you run your program, it will have access to all the functions from libft.

*As of now the instruction only partain to creating the static library on MacOS. Use on linux or windows systems at your own risk ;)


The Library

Our Libft library is divided into three sections according to intructions in the subject file:

  • Recreated/reimplemented Standard C Functions:
    These functions replicate the behavior of their standard C library (libc) counterparts.
  • Custom/extended and Alternative C Functions:
    This section introduces functions that either enhance the standard C library's capabilities or provide different ways to achieve existing functionality.
  • Linked List and Struct Operations:
    In this section, you'll discover functions and data structures designed for effective management of linked lists and structured data.

Reimplemented Libc Functions

In this section, you will find a set of functions, that are recreations of their standard C library (libc) counterparts. These custom functions mirror the behavior of their libc counterparts, following the same prototypes and adhering to the specifications outlined in their respective man pages. The only difference is their naming, as they are prefixed with 'ft_' (42, a coy reference to the school system).

For example, strlen is replicated as ft_strlen.

* * * *
ft_isalpha ft_memset ft_toupper ft_memcmp
ft_isdigit ft_bzero ft_tolower ft_strnstr
ft_isalnum ft_memcpy ft_strchr ft_atoi
ft_isascii ft_memmove ft_strrchr ft_calloc
ft_isprint ft_strlcpy ft_strncmp ft_strdup
ft_strlen ft_strlcat ft_memchr

The process of re-implementing these functions served as an introductory exercise in C programming, encompassing fundamental concepts such as algorithmic logic, data structures, memory allocation, and pointer manipulation.


Custom Libc Functions*

In this second section, we created a set of functions that either expand upon the capabilities of the standard C library (libc) or offer alternative implementations of existing functionality. These functions may address specialized requirements not covered by the standard library, or they might present optimized approaches to common tasks. This exercise encourages a deeper exploration of C programming, reinforcing proficiency in algorithmic design, data structure utilization, memory management, and advanced pointer manipulation.

* *
ft_subst ft_strjoin
ft_strtrim ft_split
ft_itoa ft_strmapi
ft_putchar_fd ft_putstr_fd
ft_putendl_fd ft_putnbr_fd

*For the requirements of the implementation of each custom function, please take a look at the link to the included subject file below.


Linked List and Struct Functions

This section of the libft library encompasses a collection of functions and data structures tailored for efficient linked list handling and structured data organization. Included are essential operations for creating, manipulating, and traversing linked lists, as well as utility functions for managing custom data structures using structs.

* *
ft_lstnew ft_lstadd_front
ft_lstsize ft_lstlast
ft_lstadd_back ft_lstdelone
ft_lstclear ft_lstiter
ft_lstmap

Remarks

Creating the static library libft marked my very first steps in the world of coding. It was both fun and challenging, albeit with occasional inaccuracies and often, less-than-efficient code.

Admittedly, as I wrote most of these functions, my grasp of the involved concepts was, at best, rudimentary. Yet, revisiting them now provides a pleasant reminder of those initial struggles, and my constant ongoing growth and improvement.

This is precisely why I've chosen not to update functions that might, to a discerning eye, display certain glaring faults. They stand as valuable markers of my progress in this coding journey.


Sources

About

A comprehensive C library that provides a collection of custom-made functions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published