Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

146 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🇨📚 Libft: The 42 library for C projects

GitHub code size in bytes Code language count GitHub top language GitHub last commit

📖 Content

  1. Project Overview

  2. Project Structure

  3. Functions List

    Show/Hide Functions List
  4. Installation

  5. Usage

    Show/Hide Usage

📝 Project Overview

Libft is a custom implementation of the C Standard Library functions. This project is part of the 42 curriculum and aims to help students become familiar with basic C programming and fundamental data structures.

📂 Project Structure

The project is structured into several categories of functions:

  • Libc Functions: Reimplementations of standard C library functions.
  • Additional Functions: Utility functions that provide common functionality missing from the C standard library.
  • Bonus Functions: Functions that handle linked lists.

📋 Function List

Table of Functions

Libc Functions Additional Functions Bonus Functions
ft_isalpha ft_substr ft_lstnew
ft_isdigit ft_strjoin ft_lstadd_front
ft_isalnum ft_strtrim ft_lstsize
ft_isascii ft_split ft_lstlast
ft_isprint ft_itoa ft_lstadd_back
ft_strlen ft_strmapi ft_lstdelone
ft_memset ft_striteri ft_lstclear
ft_bzero ft_putchar_fd ft_lstiter
ft_memcpy ft_putstr_fd ft_lstmap
ft_memmove ft_putendl_fd
ft_strlcpy ft_putnbr_fd
ft_strlcat
ft_toupper
ft_tolower
ft_strchr
ft_strrchr
ft_strncmp
ft_memchr
ft_memcmp
ft_strnstr
ft_atoi
ft_strdup
ft_calloc

Character Check Functions

Function Name Description
ft_isalpha Checks if the character is alphabetic.
ft_isdigit Checks if the character is a digit.
ft_isalnum Checks if the character is alphanumeric.
ft_isascii Checks if the character is an ASCII value.
ft_isprint Checks if the character is printable.

String Functions

String Length and Manipulation

Function Name Description
ft_strlen Calculates the length of a string.
ft_strlcpy Copies a string to a destination buffer, ensuring null-termination.
ft_strlcat Concatenates strings with size limit, ensuring null-termination.
ft_substr Extracts a substring from a string.
ft_strjoin Concatenates two strings into a new string.
ft_strtrim Trims leading and trailing whitespace or specified characters.
ft_split Splits a string into an array of strings based on a delimiter.
ft_strmapi Applies a function to each character of a string to create a new string.
ft_striteri Applies a function to each character of a string, modifying it in place.

String Comparison and Searching

Function Name Description
ft_strchr Locates the first occurrence of a character in a string.
ft_strrchr Locates the last occurrence of a character in a string.
ft_strncmp Compares two strings up to n characters.
ft_strnstr Locates a substring in a string, within the first n characters.
ft_strdup Duplicates a string by allocating memory for the new copy.

Memory Functions

Function Name Description
ft_memset Fills memory with a constant byte.
ft_bzero Sets memory to zero.
ft_memcpy Copies memory area.
ft_memmove Safely copies overlapping memory areas.
ft_memchr Searches memory for a byte.
ft_memcmp Compares two memory areas.
ft_calloc Allocates memory and initializes it to zero.

Conversion Functions

Function Name Description
ft_atoi Converts a string to an integer.
ft_itoa Converts an integer to a string.

Output Functions

Function Name Description
ft_putchar_fd Outputs a character to a file descriptor.
ft_putstr_fd Outputs a string to a file descriptor.
ft_putendl_fd Outputs a string to a file descriptor, followed by a newline.
ft_putnbr_fd Outputs an integer to a file descriptor.

Linked List Functions

Function Name Description
ft_lstnew Creates a new list element.
ft_lstadd_front Adds an element to the beginning of the list.
ft_lstsize Counts the number of elements in the list.
ft_lstlast Returns the last element of the list.
ft_lstadd_back Adds an element to the end of the list.
ft_lstdelone Deletes a single list element.
ft_lstclear Clears the entire list.
ft_lstiter Iterates over the list and applies a function to each element.
ft_lstmap Applies a function to each element of the list and creates a new list with the results.

🛠️ Installation

To install and use the libft library, follow these steps:

  1. Clone the repository to your local machine:

    git clone https://github.com/BenzThor/libft.h.git
    cd libft
  2. Compile the library:

    make
  3. The above command will generate a libft.a file, which is a static library that you can link to your C projects.

🚀 Usage

General Usage

To use the libft library in your project, follow these steps:

  1. Include the libft.h header in your source files:

    #include "libft.h"
  2. Link the libft.a library during compilation:

    gcc -Wall -Wextra -Werror -o your_program your_program.c -L. -lft
  3. Run your program:

    ./your_program

GCC Command Explanation

Command Breakdown

The gcc command is used for compiling and linking programs. Here's a breakdown of the command and its components:

gcc

The GNU Compiler Collection command for compiling and linking.

Flags

  • -Wall: Enable all standard warnings.
  • -Wextra: Enable additional warnings not covered by -Wall.
  • -Werror: Treat all warnings as errors.

Output File

  • -o your_program: Specifies the output file name for your compiled program.

Source Code File

  • your_program.c: The source code file to be compiled.

Library Directories and Linking

  • -L.: Tells the compiler to look for libraries in the current directory (denoted by .). This is where libft.a is located.
  • -lft: Tells the linker to link against the libft library. The -l flag is followed by the name of the library without the lib prefix and the .a suffix. In this case, libft.a corresponds to -lft.

Additional Notes

  • Library Path: If libft.a is located in a different directory, replace . in -L. with the path to that directory. For example, if libft.a is in ./lib, you would use -L./lib.

  • Static vs. Dynamic Linking: libft.a is a static library. This means that the library code is included directly into your executable. If you were using a dynamic library (.so file), the linking process would be slightly different.

  • Compilation and Linking Order: Ensure that you include the library linking flags (-L and -l) after your source files in the gcc command. This ensures that the linker resolves symbols from the library correctly.

About

Libft is a custom implementation of the C Standard Library functions. This project is part of the 42 curriculum and aims to help students become familiar with basic C programming and fundamental data structures.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages