/Libft

An open source standard C library that includes useful functions (Refactoring some libc functions + our own functions).

Primary LanguageC


📖 LIBFT-42 :


Subject :


📖 ENGLISH PDF


ℹ️ What exactly is LIBFT ?


This project aims to code a C library regrouping usual functions that you’ll be allowed to use in all your other projects.


🔧 🔧 Mandatory parts [part I] [part II] :


Part I :


In this first part, you must re-code a set of the libc functions, as defined in their man. Your functions will need to present the same prototype and behaviors as the originals. Your functions’ names must be prefixed by “ft_”. For instance strlen becomes ft_strlen.


# Assignement name Description
libft.h Contains all prototypes of functions and structures.

FUNCTION Allowed functions Prototype Description Library
isalpha() NONE int ft_isalpha (int c) Checks for an alphabetic character. <ctype.h>
isdigit() NONE int ft_isdigit (int c) Checks for a digit (0 through 9). <ctype.h>
isalnum() NONE int ft_isalnum (int c) Checks for an alphanumeric character. <ctype.h>
isascii() NONE int ft_isascii (int c) Checks whether c fits into the ASCII character set. <ctype.h>
isprint() NONE int ft_isprint (int c) Checks for any printable character. <ctype.h>
strlen() NONE size_t strlen(const char *s) Calculate the length of a string. <string.h>
memset() NONE void *ft_memset(void *b, int c, size_t len) Fill memory with a constant byte. <string.h>
bzero() NONE void ft_bzero(void *s, size_t n) Zero a byte string. <string.h>
memcpy() NONE void *ft_memcpy(void *dest, const void *src, size_t n) Copy memory area. <string.h>
memmove() NONE void *ft_memmove(void *dst, const void *src, size_t len) Function copies n bytes from memory area src to memory area dest. <string.h>
strlcpy() NONE size_t ft_strlcpy(char *dst, const char *src, size_t dstlen) Copy string to a specific size. <string.h>
strlcat() NONE size_t ft_strlcat(char *dst, const char *src, size_t dstsize) Concatenate string to a specific size. <string.h>
toupper() NONE int ft_toupper(int c) Convert chat to uppercase <ctype.h>
tolower() NONE int ft_tolower(int c) Convert char to lowercase. <ctype.h>
strchr() NONE char *ft_strchr(const char *s, int c) Locate character in string (first occurrence). <string.h>
strrchr() NONE char *ft_strrchr(const char *s, int c) Locate character in string (last occurrence). <string.h>
strncmp() NONE int ft_strncmp(const char *s1, const char *s2, size_t n) Compare n bytes of two strings. <string.h>
memchr() NONE void *ft_memchr(const void *s, int c, size_t n) Scan memory for a character. <string.h>
memcmp() NONE int ft_memcmp(const void *s1, const void *s2, size_t n) Compare memory areas. <string.h>
strnstr() NONE char *ft_strnstr(const char *haystack, const char *needle, size_t len) Locate a substring in a string. <string.h>
atoi() NONE int ft_atoi(const char *s) <stdlib.h>

The legend says : "READ THE FUCKING MANUAL." X) !


# FUNCTION MANUAL
isalpha man
isdigit man
isalnum man
isascii man
strlen man
memset man
bzero man
memcpy man
memmove man
strlcpy man
strlcat man
toupper man
tolower man
strchr man
strncmp() man
memchr() man
memcmp() man
strnstr() man
atoi() man

You must also re-code the following functions, using the function “malloc”: | Function | Allowed function | Prototype | Description | Manual | |--- |--- |--- |--- |--- | | •strdup | malloc() | char *ft_strdup(const char *s) | Duplicate a string. | man | | • calloc | malloc() | void *ft_calloc(size_t count, size_t size); | Allocate memory by filling it with zeros. | man |


🔧 🏭 Additional functions :


Part II :


In this second part, you must code a set of functions that are either not included in the libc, or included in a different form. Some of these functions can be useful to write Part 1’s functions.

FUNCTION BEHAVIOR
- ft_substr - returns a substring from a string
- ft_strjoin.c - concatenates two strings
- ft_strtrim.c - trims the beginning and end of string with specific set of chars
- ft_split.c - splits a string using a char as parameter
- ft_itoa.c - converts a number into a string
- ft_strmapi.c - applies a function to each character of a string
- ft_striteri.c - applies a function to each character of a string
- ft_putchar_fd.c - output a char to a file descriptor
- ft_putstr_fd.c - output a string to a file descriptor
- ft_putendl_fd.c - output a string to a file descriptor, followed by a new line
- ft_putnbr_fd.c - output a number to a file descriptor


🔧 ✅ BONUS :


The following functions will allow you to easily use your lists.

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