Skip to content

Latest commit

 

History

History
141 lines (124 loc) · 5.89 KB

README.md

File metadata and controls

141 lines (124 loc) · 5.89 KB

Libft - Your Own C Library

Introduction

Libft is a project aimed at creating your own C library—a collection of useful functions that you'll be able to use in future C programming projects. The goal is to recreate standard C library functions and add additional ones that will come in handy throughout your coding journey.

Project Structure

Source Files (.c)

All function implementations are placed here, with each function in its own file. Naming conventions should follow the pattern of the function name, for example:

  • ft_strlen.c
  • ft_strdup.c
  • etc.

Header File (libft.h)

The header file contains declarations for all your functions. It should:

  • Include all necessary libraries (e.g., #include <unistd.h>, etc.)
  • Declare all function prototypes
  • Be included in every .c file using #include "libft.h"

Makefile

The Makefile is responsible for compiling the library. It should:

  • Compile all .c files into object files
  • Create the static library libft.a
  • Include rules for clean, fclean, and re

Functions to Implement

Functions from <ctype.h>

  • ft_isalpha - checks if the character is alphabetic
  • ft_isdigit - checks if the character is a digit (0 through 9)
  • ft_isalnum - checks if the character is alphanumeric
  • ft_isascii - checks if the character is part of the ASCII set
  • ft_isprint - checks if the character is printable
  • ft_toupper - converts the character to uppercase
  • ft_tolower - converts the character to lowercase

Functions from <string.h>

  • ft_memset - fills memory with a constant byte
  • ft_strlen - calculates the length of a string
  • ft_bzero - zeroes out a byte string
  • ft_memcpy - copies memory from one area to another
  • ft_memmove - safely copies memory even if regions overlap
  • ft_strlcpy - copies a string up to a specified size
  • ft_strlcat - concatenates two strings up to a specified size
  • ft_strchr - locates a character in a string
  • ft_strrchr - locates a character in a string, searching from the end
  • ft_strncmp - compares two strings
  • ft_memchr - scans memory for a character
  • ft_memcmp - compares two memory areas
  • ft_strnstr - locates a substring within a string
  • ft_strdup - duplicates a string

Functions from <stdlib.h>

  • ft_atoi - converts a string to an integer
  • ft_calloc - allocates memory and sets it to zero

Additional Functions

  • ft_substr - returns a substring from a string
  • ft_strjoin - concatenates two strings
  • ft_strtrim - trims specified characters from the beginning and end of a string
  • ft_split - splits a string using a character as a delimiter
  • ft_itoa - converts an integer to a string
  • ft_strmapi - applies a function to each character of a string
  • ft_striteri - applies a function to each character of a string using the index
  • ft_putchar_fd - outputs a character to the given file descriptor
  • ft_putstr_fd - outputs a string to the given file descriptor
  • ft_putendl_fd - outputs a string followed by a newline to the given file descriptor
  • ft_putnbr_fd - outputs a number to the given file descriptor

Bonus Part: Linked List Functions

If you've finished the mandatory part, you can implement a set of linked list functions:

  • ft_lstnew - creates a new list element
  • ft_lstadd_front - adds an element at the beginning of the list
  • ft_lstsize - counts the number of elements in the list
  • ft_lstlast - returns the last element in the list
  • ft_lstadd_back - adds an element to the end of the list
  • ft_lstclear - deletes and frees the list
  • ft_lstiter - applies a function to each element of the list
  • ft_lstmap - applies a function to each element of the list, creating a new list

Core Features

Memory Management Functions

Function Description Memory Usage Cycles (Typical)
ft_memset Fill memory with constant byte O(n) n + 3
ft_bzero Zero out a byte string O(n) n + 2
ft_memcpy Copy memory area O(n) n + 4
ft_memmove Safe memory copy with overlap O(n) n + 6

Conclusion

Libft is the foundation for your future C projects. It equips you with a set of essential tools and is a key step in mastering C programming. Happy coding!