mirror of
https://github.com/Ladebeze66/libft.git
synced 2025-12-13 04:36:55 +01:00
libft
This commit is contained in:
commit
13bbc97671
111
Makefile
Executable file
111
Makefile
Executable file
@ -0,0 +1,111 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/02/06 12:19:21 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/12/07 11:25:50 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
RST = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
NAME = libft.a
|
||||
|
||||
SOURCES = ft_atoi.c \
|
||||
ft_isalpha.c \
|
||||
ft_memchr.c \
|
||||
ft_memset.c \
|
||||
ft_strlcat.c \
|
||||
ft_strnstr.c \
|
||||
ft_toupper.c \
|
||||
ft_bzero.c \
|
||||
ft_isascii.c \
|
||||
ft_memcmp.c \
|
||||
ft_strchr.c \
|
||||
ft_strlcpy.c \
|
||||
ft_strrchr.c \
|
||||
ft_calloc.c \
|
||||
ft_isdigit.c \
|
||||
ft_memcpy.c \
|
||||
ft_strdup.c \
|
||||
ft_strlen.c \
|
||||
ft_substr.c \
|
||||
ft_isalnum.c \
|
||||
ft_isprint.c \
|
||||
ft_memmove.c \
|
||||
ft_strjoin.c \
|
||||
ft_strncmp.c \
|
||||
ft_tolower.c\
|
||||
ft_strtrim.c \
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
ft_strmapi.c \
|
||||
ft_striteri.c \
|
||||
ft_split.c \
|
||||
ft_itoa.c \
|
||||
ft_strcmp.c \
|
||||
ft_strstr.c \
|
||||
ft_reallocarray.c \
|
||||
ft_strcat.c \
|
||||
ft_strcpy.c \
|
||||
ft_realloc.c \
|
||||
ft_strncpy.c \
|
||||
ft_strtol.c \
|
||||
ft_strtok.c \
|
||||
|
||||
SRCBONUS = ft_lstnew.c \
|
||||
ft_lstadd_front.c \
|
||||
ft_lstsize.c \
|
||||
ft_lstlast.c \
|
||||
ft_lstadd_back.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstclear.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
|
||||
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
|
||||
BONUS_OBJ = $(SRCBONUS:.c=.o)
|
||||
|
||||
CC = gcc
|
||||
|
||||
RM = rm -f
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJECTS)
|
||||
@ar rcs $(NAME) $(OBJECTS)
|
||||
|
||||
bonus: $(OBJECTS) $(BONUS_OBJ)
|
||||
@ar rcs $(NAME) $(OBJECTS) $(BONUS_OBJ)
|
||||
|
||||
main.o:
|
||||
gcc -c main.c
|
||||
|
||||
ccmainlib:
|
||||
$(CC) $(CFLAGS) main.c -L -lft
|
||||
|
||||
clean:
|
||||
@$(RM) $(OBJECTS) $(BONUS_OBJ)
|
||||
|
||||
fclean: clean
|
||||
@$(RM) $(NAME)
|
||||
|
||||
re: fclean all
|
||||
540
fr.subject.pdf
Normal file
540
fr.subject.pdf
Normal file
@ -0,0 +1,540 @@
|
||||
Libft
|
||||
|
||||
Ta propre bibliothèque rien que pour toi
|
||||
|
||||
Résumé:
|
||||
Ce projet a pour objectif de vous faire coder en C une bibliothèque de fonctions usuelles
|
||||
|
||||
que vous pourrez utiliser pour vos prochains projets.
|
||||
Version: 16
|
||||
Table des matières
|
||||
|
||||
I Introduction 2
|
||||
|
||||
II Règles communes 3
|
||||
|
||||
III Partie obligatoire 4
|
||||
|
||||
III.1 Considérations techniques . . . . . . . . . . . . . . . . . . . . . . . . . 4
|
||||
|
||||
III.2 Partie 1 - Fonctions de la libc . . . . . . . . . . . . . . . . . . . . . . 5
|
||||
|
||||
III.3 Partie 2 - Fonctions supplémentaires . . . . . . . . . . . . . . . . . . . 6
|
||||
|
||||
IV Partie bonus 10
|
||||
|
||||
V Rendu et peer-evaluation 14
|
||||
|
||||
1
|
||||
Chapitre I
|
||||
Introduction
|
||||
|
||||
La programmation en C est une activité très laborieuse dès lors que l’on n’a pas accès
|
||||
à toutes ces petites fonctions usuelles très pratiques. C’est pourquoi nous vous proposons
|
||||
à travers ce projet de prendre le temps de récrire ces fonctions, de les comprendre et
|
||||
de vous les approprier. Vous pourrez alors réutiliser votre bibliothèque pour travailler
|
||||
efficacement sur vos projets suivants en C.
|
||||
|
||||
Prenez le temps d’enrichir votre libft tout au long de l’année. Cependant, pour
|
||||
chacun de vos projets futurs, veillez toujours à vérifier quelles sont les fonctions autorisées !
|
||||
|
||||
2
|
||||
Chapitre II
|
||||
|
||||
Règles communes
|
||||
|
||||
• Votre projet doit être écrit en C.
|
||||
|
||||
• Votre projet doit être codé à la Norme. Si vous avez des fichiers ou fonctions bonus,
|
||||
celles-ci seront inclues dans la vérification de la norme et vous aurez 0 au projet
|
||||
en cas de faute de norme.
|
||||
|
||||
• Vos fonctions ne doivent pas s’arrêter de manière inattendue (segmentation fault,
|
||||
bus error, double free, etc) mis à part dans le cas d’un comportement indéfini. Si
|
||||
cela arrive, votre projet sera considéré non fonctionnel et vous aurez 0 au projet.
|
||||
|
||||
• Toute mémoire allouée sur la heap doit être libéré lorsque c’est nécessaire. Aucun
|
||||
leak ne sera toléré.
|
||||
|
||||
• Si le projet le demande, vous devez rendre un Makefile qui compilera vos sources
|
||||
pour créer la sortie demandée, en utilisant les flags -Wall, -Wextra et -Werror.
|
||||
Votre Makefile ne doit pas relink.
|
||||
|
||||
• Si le projet demande un Makefile, votre Makefile doit au minimum contenir les
|
||||
règles $(NAME), all, clean, fclean et re.
|
||||
|
||||
• Pour rendre des bonus, vous devez inclure une règle bonus à votre Makefile qui
|
||||
ajoutera les divers headers, librairies ou fonctions qui ne sont pas autorisées dans
|
||||
la partie principale du projet. Les bonus doivent être dans un fichier différent :
|
||||
_bonus.{c/h}. L’évaluation de la partie obligatoire et de la partie bonus sont
|
||||
faites séparément.
|
||||
|
||||
• Si le projet autorise votre libft, vous devez copier ses sources et son Makefile
|
||||
associé dans un dossier libft contenu à la racine. Le Makefile de votre projet doit
|
||||
compiler la librairie à l’aide de son Makefile, puis compiler le projet.
|
||||
|
||||
• Nous vous recommandons de créer des programmes de test pour votre projet, bien
|
||||
que ce travail ne sera pas rendu ni noté. Cela vous donnera une chance de
|
||||
tester facilement votre travail ainsi que celui de vos pairs.
|
||||
|
||||
• Vous devez rendre votre travail sur le git qui vous est assigné. Seul le travail déposé
|
||||
sur git sera évalué. Si Deepthought doit corriger votre travail, cela sera fait à la fin
|
||||
des peer-evaluations. Si une erreur se produit pendant l’évaluation Deepthought,
|
||||
celle-ci s’arrête.
|
||||
|
||||
3
|
||||
Chapitre III
|
||||
Partie obligatoire
|
||||
|
||||
Nom du pro- libft.a
|
||||
|
||||
gramme Makefile, libft.h, ft_*.c
|
||||
NAME, all, clean, fclean, re
|
||||
Fichiers de rendu Détails ci-dessous
|
||||
|
||||
Makefile n/a
|
||||
Créez votre propre bibliothèque contenant des
|
||||
Fonctions ex- fonctions utiles pour la suite de votre cursus.
|
||||
|
||||
ternes autorisées
|
||||
|
||||
Libft autorisée
|
||||
|
||||
Description
|
||||
|
||||
III.1 Considérations techniques
|
||||
|
||||
• Interdiction d’utiliser des variables globales.
|
||||
|
||||
• Si vous avez besoin de fonctions auxiliaires pour réaliser une fonction complexe,
|
||||
vous devez définir ces dernières en static dans le respect de la Norme. Ainsi, leur
|
||||
portée sera limitée au fichier concerné.
|
||||
|
||||
• Vous devez rendre tous vos fichiers à la racine de votre dépôt.
|
||||
|
||||
• Il est interdit de rendre des fichiers non utilisés.
|
||||
|
||||
• Chaque fichier .c doit être compilé avec les flags -Wall -Wextra -Werror.
|
||||
• Vous devez utiliser la commande ar pour créer votre bibliothèque. L’utilisation de
|
||||
|
||||
la commande libtool est interdite.
|
||||
• Votre libft.a doit être créé à la racine de votre dépôt.
|
||||
|
||||
4
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
III.2 Partie 1 - Fonctions de la libc
|
||||
|
||||
Dans cette première partie, vous devez recoder un ensemble de fonctions de la libc
|
||||
telles que décrites dans leur man respectif sur votre système. Vos fonctions devront avoir
|
||||
exactement le même prototype et le même comportement que les originales. Seule diffé-
|
||||
rence, leur nom devra être préfixé par ’ft_’. Ainsi, strlen devient ft_strlen.
|
||||
|
||||
Certains prototypes des fonctions que vous devez recoder utilisent le
|
||||
qualifieur de type ’restrict’. Ce mot-clé fait parti du standard c99.
|
||||
Par conséquent, vous ne devez pas l’utiliser pour vos prototypes et
|
||||
ne pas compiler votre code avec le flag -std=c99.
|
||||
|
||||
Vous devez recoder les fonctions suivantes. Elles ne nécessitent aucune fonction ex-
|
||||
terne :
|
||||
|
||||
• isalpha • toupper
|
||||
• isdigit • tolower
|
||||
• isalnum • strchr
|
||||
• isascii • strrchr
|
||||
• isprint • strncmp
|
||||
• strlen • memchr
|
||||
• memset • memcmp
|
||||
• bzero • strnstr
|
||||
• memcpy • atoi
|
||||
• memmove
|
||||
• strlcpy
|
||||
• strlcat
|
||||
|
||||
Pour les deux fonctions suivantes, vous pourrez faire appel à la fonction malloc() :
|
||||
|
||||
• calloc
|
||||
• strdup
|
||||
|
||||
5
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
III.3 Partie 2 - Fonctions supplémentaires
|
||||
|
||||
Dans cette seconde partie, vous devrez implémenter un certain nombre de fonctions
|
||||
absentes de la libc, ou qui y sont mais sous une forme différente.
|
||||
|
||||
Certaines de ces fonctions peuvent faciliter l’écriture des fonctions
|
||||
demandées dans la Partie 1.
|
||||
|
||||
Function name ft_substr
|
||||
Prototype char *ft_substr(char const *s, unsigned int start,
|
||||
size_t len);
|
||||
Fichiers de rendu -
|
||||
Paramètres s: La chaîne de laquelle extraire la nouvelle
|
||||
chaîne.
|
||||
Valeur de retour start: L’index de début de la nouvelle chaîne dans
|
||||
la chaîne ’s’.
|
||||
Fonctions ex- len: La taille maximale de la nouvelle chaîne.
|
||||
La nouvelle chaîne de caractères.
|
||||
ternes autorisées NULL si l’allocation échoue.
|
||||
malloc
|
||||
Description
|
||||
Alloue (avec malloc(3)) et retourne une chaîne de
|
||||
caractères issue de la chaîne ’s’.
|
||||
Cette nouvelle chaîne commence à l’index ’start’ et
|
||||
a pour taille maximale ’len’.
|
||||
|
||||
Function name ft_strjoin
|
||||
Prototype char *ft_strjoin(char const *s1, char const *s2);
|
||||
Fichiers de rendu -
|
||||
Paramètres s1: La chaîne de caractères préfixe.
|
||||
s2: La chaîne de caractères suffixe.
|
||||
Valeur de retour La nouvelle chaîne de caractères.
|
||||
NULL si l’allocation échoue.
|
||||
Fonctions ex- malloc
|
||||
|
||||
ternes autorisées Alloue (avec malloc(3)) et retourne une nouvelle
|
||||
chaîne, résultat de la concaténation de s1 et s2.
|
||||
Description
|
||||
|
||||
6
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
Function name ft_strtrim
|
||||
Prototype char *ft_strtrim(char const *s1, char const *set);
|
||||
Fichiers de rendu -
|
||||
Paramètres s1: La chaîne de caractères à trimmer.
|
||||
set: Le set de référence de caractères à trimmer.
|
||||
Valeur de retour La chaîne de caractères trimmée.
|
||||
NULL si l’allocation échoue.
|
||||
Fonctions ex- malloc
|
||||
|
||||
ternes autorisées Alloue (avec malloc(3)) et retourne une copie de
|
||||
la chaîne ’s1’, sans les caractères spécifiés
|
||||
Description dans ’set’ au début et à la fin de la chaîne de
|
||||
caractères.
|
||||
|
||||
Function name ft_split
|
||||
Prototype char **ft_split(char const *s, char c);
|
||||
Fichiers de rendu -
|
||||
Paramètres s: La chaîne de caractères à découper.
|
||||
c: Le caractère délimiteur.
|
||||
Valeur de retour Le tableau de nouvelles chaînes de caractères
|
||||
résultant du découpage.
|
||||
Fonctions ex- NULL si l’allocation échoue.
|
||||
malloc, free
|
||||
ternes autorisées
|
||||
Alloue (avec malloc(3)) et retourne un tableau
|
||||
Description de chaînes de caractères obtenu en séparant ’s’ à
|
||||
l’aide du caractère ’c’, utilisé comme délimiteur.
|
||||
Le tableau doit être terminé par NULL.
|
||||
|
||||
Function name ft_itoa
|
||||
Prototype char *ft_itoa(int n);
|
||||
Fichiers de rendu -
|
||||
Paramètres n: L’entier à convertir.
|
||||
Valeur de retour La chaîne de caractères représentant l’entier.
|
||||
NULL si l’allocation échoue.
|
||||
Fonctions ex- malloc
|
||||
|
||||
ternes autorisées Alloue (avec malloc(3)) et retourne une chaîne
|
||||
de caractères représentant l’entier ’n’ reçu en
|
||||
Description argument. Les nombres négatifs doivent être gérés.
|
||||
|
||||
7
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
Function name ft_strmapi
|
||||
Prototype char *ft_strmapi(char const *s, char (*f)(unsigned
|
||||
int, char));
|
||||
Fichiers de rendu -
|
||||
Paramètres s: La chaîne de caractères sur laquelle itérer.
|
||||
f: La fonction à appliquer à chaque caractère.
|
||||
Valeur de retour La chaîne de caractères résultant des applications
|
||||
successives de ’f’.
|
||||
Fonctions ex- Retourne NULL si l’allocation échoue.
|
||||
malloc
|
||||
ternes autorisées
|
||||
Applique la fonction ’f’ à chaque caractère de la
|
||||
Description chaîne de caractères passée en argument pour créer
|
||||
une nouvelle chaîne de caractères (avec malloc(3))
|
||||
résultant des applications successives de ’f’.
|
||||
|
||||
Function name ft_striteri
|
||||
Prototype void ft_striteri(char *s, void (*f)(unsigned int,
|
||||
char*));
|
||||
Fichiers de rendu -
|
||||
Paramètres s: La chaîne de caractères sur laquelle itérer.
|
||||
f: La fonction à appliquer à chaque caractère.
|
||||
Valeur de retour Aucune
|
||||
Aucune
|
||||
Fonctions ex-
|
||||
Applique la fonction ’f’ à chaque caractère de la
|
||||
ternes autorisées chaîne de caractères transmise comme argument,
|
||||
et en passant son index comme premier argument.
|
||||
Description Chaque caractère est transmis par adresse à ’f’
|
||||
afin d’être modifié si nécessaire.
|
||||
|
||||
Function name ft_putchar_fd
|
||||
Prototype void ft_putchar_fd(char c, int fd);
|
||||
Fichiers de rendu -
|
||||
Paramètres c: Le caractère à écrire.
|
||||
fd: Le descripteur de fichier sur lequel écrire.
|
||||
Valeur de retour Aucune
|
||||
write
|
||||
Fonctions ex-
|
||||
Écrit le caractère ’c’ sur le descripteur de
|
||||
ternes autorisées fichier donné.
|
||||
|
||||
Description
|
||||
|
||||
8
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
Function name ft_putstr_fd
|
||||
Prototype void ft_putstr_fd(char *s, int fd);
|
||||
Fichiers de rendu -
|
||||
Paramètres s: La chaîne de caractères à écrire.
|
||||
fd: Le descripteur de fichier sur lequel écrire.
|
||||
Valeur de retour Aucune
|
||||
write
|
||||
Fonctions ex-
|
||||
Écrit la chaîne de caractères ’s’ sur le
|
||||
ternes autorisées descripteur de fichier donné.
|
||||
|
||||
Description
|
||||
|
||||
Function name ft_putendl_fd
|
||||
Prototype void ft_putendl_fd(char *s, int fd);
|
||||
Fichiers de rendu -
|
||||
Paramètres s: La chaîne de caractères à écrire.
|
||||
fd: Le descripteur de fichier sur lequel écrire.
|
||||
Valeur de retour Aucune
|
||||
write
|
||||
Fonctions ex-
|
||||
Écrit La chaîne de caractères ’s’ sur le
|
||||
ternes autorisées descripteur de fichier donné suivie d’un retour à
|
||||
la ligne.
|
||||
Description
|
||||
|
||||
Function name ft_putnbr_fd
|
||||
Prototype void ft_putnbr_fd(int n, int fd);
|
||||
Fichiers de rendu -
|
||||
Paramètres n: L’entier à écrire.
|
||||
fd: Le descripteur de fichier sur lequel écrire.
|
||||
Valeur de retour Aucune
|
||||
write
|
||||
Fonctions ex-
|
||||
Écrit l’entier ’n’ sur le descripteur de fichier
|
||||
ternes autorisées donné.
|
||||
|
||||
Description
|
||||
|
||||
9
|
||||
Chapitre IV
|
||||
Partie bonus
|
||||
|
||||
Si vous avez réussi parfaitement la partie obligatoire, cette section propose quelques
|
||||
pistes pour aller plus loin. Un peu comme quand vous achetez un DLC pour un jeu vidéo.
|
||||
|
||||
Avoir des fonctions de manipulation de mémoire brute et de chaînes de caractères est
|
||||
très pratique. Toutefois, vous vous rendrez vite compte qu’avoir des fonctions de mani-
|
||||
pulation de listes est encore plus pratique.
|
||||
|
||||
Vous utiliserez la structure suivante pour représenter les maillons de votre liste. Sa
|
||||
déclaration est à ajouter à votre fichier libft.h :
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
*content;
|
||||
void *next;
|
||||
struct s_list t_list;
|
||||
}
|
||||
|
||||
Les membres de la structure t_list sont les suivants :
|
||||
|
||||
• content : La donnée contenue dans le maillon.
|
||||
void * permet de stocker une donnée de n’importe quel type.
|
||||
|
||||
• next : L’adresse du maillon suivant de la liste, ou NULL si le maillon suivant est le
|
||||
dernier.
|
||||
|
||||
Dans votre Makefile, une règle make bonus vous permettra d’ajouter les fonctions
|
||||
demandées à votre libft.a.
|
||||
|
||||
Vous ne devez pas suffixer vos fichiers .c et vos fichiers d’en-tête avec _bonus. En effet,
|
||||
ajoutez le suffixe _bonus seulement aux fichiers supplémentaires réalisés exclusivement
|
||||
pour la partie bonus.
|
||||
|
||||
Les bonus ne seront évalués que si la partie obligatoire est
|
||||
PARFAITE. Par parfaite, nous entendons complète et sans aucun
|
||||
dysfonctionnement. Si vous n’avez pas réussi TOUS les points de la
|
||||
partie obligatoire, votre partie bonus ne sera pas prise en compte.
|
||||
|
||||
10
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
Implémentez les fonctions suivantes afin de manipuler vos listes aisément.
|
||||
|
||||
Function name ft_lstnew
|
||||
t_list *ft_lstnew(void *content);
|
||||
Prototype -
|
||||
content: Le contenu du nouvel élément.
|
||||
Fichiers de rendu Le nouvel élément
|
||||
malloc
|
||||
Paramètres
|
||||
Alloue (avec malloc(3)) et renvoie un nouvel
|
||||
Valeur de retour élément. La variable membre ’content’ est
|
||||
initialisée à l’aide de la valeur du paramètre
|
||||
Fonctions ex- ’content’. La variable ’next’ est initialisée à
|
||||
NULL.
|
||||
ternes autorisées
|
||||
|
||||
Description
|
||||
|
||||
Function name ft_lstadd_front
|
||||
Prototype void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
Fichiers de rendu -
|
||||
Paramètres lst: L’adresse du pointeur vers le premier élément
|
||||
de la liste.
|
||||
Valeur de retour new: L’adresse du pointeur vers l’élément à
|
||||
rajouter à la liste.
|
||||
Fonctions ex- Aucune
|
||||
Aucune
|
||||
ternes autorisées
|
||||
Ajoute l’élément ’new’ au début de la liste.
|
||||
Description
|
||||
|
||||
Function name ft_lstsize
|
||||
int ft_lstsize(t_list *lst);
|
||||
Prototype -
|
||||
lst: Le début de la liste.
|
||||
Fichiers de rendu Taille de la liste
|
||||
Aucune
|
||||
Paramètres
|
||||
Compte le nombre d’éléments de la liste.
|
||||
Valeur de retour
|
||||
|
||||
Fonctions ex-
|
||||
|
||||
ternes autorisées
|
||||
|
||||
Description
|
||||
|
||||
Function name ft_lstlast
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
Prototype -
|
||||
lst: Le début de la liste.
|
||||
Fichiers de rendu Dernier élément de la liste
|
||||
Aucune
|
||||
Paramètres
|
||||
Renvoie le dernier élément de la liste.
|
||||
Valeur de retour
|
||||
|
||||
Fonctions ex-
|
||||
|
||||
ternes autorisées
|
||||
|
||||
Description
|
||||
|
||||
11
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
Function name ft_lstadd_back
|
||||
Prototype void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
Fichiers de rendu -
|
||||
Paramètres lst: L’adresse du pointeur vers le premier élément
|
||||
de la liste.
|
||||
Valeur de retour new: L’adresse du pointeur vers l’élément à
|
||||
rajouter à la liste.
|
||||
Fonctions ex- Aucune
|
||||
Aucune
|
||||
ternes autorisées
|
||||
Ajoute l’élément ’new’ à la fin de la liste.
|
||||
Description
|
||||
|
||||
Function name ft_lstdelone
|
||||
Prototype void ft_lstdelone(t_list *lst, void (*del)(void
|
||||
*));
|
||||
Fichiers de rendu -
|
||||
Paramètres lst: L’élément à free
|
||||
del: L’adresse de la fonction permettant de
|
||||
Valeur de retour supprimer le contenu de l’élément.
|
||||
Aucune
|
||||
Fonctions ex- free
|
||||
|
||||
ternes autorisées Libère la mémoire de l’élément passé en argument en
|
||||
utilisant la fonction ’del’ puis avec free(3). La
|
||||
Description mémoire de ’next’ ne doit pas être free.
|
||||
|
||||
Function name ft_lstclear
|
||||
Prototype void ft_lstclear(t_list **lst, void (*del)(void
|
||||
*));
|
||||
Fichiers de rendu -
|
||||
Paramètres lst: L’adresse du pointeur vers un élément.
|
||||
del: L’adresse de la fonction permettant de
|
||||
Valeur de retour supprimer le contenu d’un élément.
|
||||
Aucune
|
||||
Fonctions ex- free
|
||||
|
||||
ternes autorisées Supprime et libère la mémoire de l’élément passé en
|
||||
paramètre, et de tous les éléments qui suivent, à
|
||||
Description l’aide de ’del’ et de free(3)
|
||||
Enfin, le pointeur initial doit être mis à NULL.
|
||||
|
||||
12
|
||||
Libft Ta propre bibliothèque rien que pour toi
|
||||
|
||||
Function name ft_lstiter
|
||||
Prototype void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
Fichiers de rendu -
|
||||
Paramètres lst: L’adresse du pointeur vers un élément.
|
||||
f: L’adresse de la fonction à appliquer.
|
||||
Valeur de retour Aucune
|
||||
Aucune
|
||||
Fonctions ex-
|
||||
Itère sur la liste ’lst’ et applique la fonction
|
||||
ternes autorisées ’f’ au contenu chaque élément.
|
||||
|
||||
Description
|
||||
|
||||
Function name ft_lstmap
|
||||
Prototype t_list *ft_lstmap(t_list *lst, void *(*f)(void *),
|
||||
void (*del)(void *));
|
||||
Fichiers de rendu -
|
||||
Paramètres lst: L’adresse du pointeur vers un élément.
|
||||
f: L’adresse de la fonction à appliquer.
|
||||
Valeur de retour del: L’adresse de la fonction permettant de
|
||||
supprimer le contenu d’un élément.
|
||||
Fonctions ex- La nouvelle liste.
|
||||
NULL si l’allocation échoue
|
||||
ternes autorisées malloc, free
|
||||
|
||||
Description Itère sur la liste ’lst’ et applique la fonction
|
||||
’f ’au contenu de chaque élément. Crée une nouvelle
|
||||
liste résultant des applications successives de
|
||||
’f’. La fonction ’del’ est là pour détruire le
|
||||
contenu d’un élément si nécessaire.
|
||||
|
||||
13
|
||||
Chapitre V
|
||||
Rendu et peer-evaluation
|
||||
|
||||
Rendez votre travail sur votre dépot Git comme d’habitude. Seul le travail présent
|
||||
sur votre dépot sera évalué en soutenance. Vérifiez bien les noms de vos dossiers et de
|
||||
vos fichiers afin que ces derniers soient conformes aux demandes du sujet.
|
||||
|
||||
Vous devez rendre tous vos fichiers à la racine de votre dépôt.
|
||||
|
||||
Rnpu cebwrpg bs gur 97 Pbzzba Pber pbagnvaf na rapbqrq uvag. Sbe rnpu
|
||||
pvepyr, bayl bar cebwrpg cebivqrf gur pbeerpg uvag arrqrq sbe gur
|
||||
arkg pvepyr. Guvf punyyratr vf vaqvivqhny, gurer vf bayl n cevmr sbe
|
||||
bar fghqrag jvaare cebivqvat nyy qrpbqrq zrffntrf. Nal nqinagntrq
|
||||
crbcyr pna cynl, yvxr pheerag be sbezre fgnss, ohg gur cevmr jvyy
|
||||
erznva flzobyvp. Gur uvag sbe guvf svefg cebwrpg vf:
|
||||
Ynetr pbjf trarebfvgl pbzrf jvgu punegf naq sbhe oybaqr ungf gb qrsl
|
||||
hccre tenivgl ureb
|
||||
|
||||
14
|
||||
|
||||
38
ft_atoi.c
Executable file
38
ft_atoi.c
Executable file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 16:16:54 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 09:57:55 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int i;
|
||||
int sign;
|
||||
int res;
|
||||
|
||||
i = 0;
|
||||
sign = 1;
|
||||
res = 0;
|
||||
while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13))
|
||||
i++;
|
||||
if (nptr[i] == '-' || nptr[i] == '+')
|
||||
{
|
||||
if (nptr[i] == '-')
|
||||
sign = - (1);
|
||||
i++;
|
||||
}
|
||||
while (nptr[i] >= 48 && nptr[i] <= 57)
|
||||
{
|
||||
res = res * 10 + nptr[i] - 48;
|
||||
i++;
|
||||
}
|
||||
return (res * sign);
|
||||
}
|
||||
25
ft_bzero.c
Executable file
25
ft_bzero.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/04 11:37:30 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:07:19 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *ptr, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
*(char *)(ptr + i) = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
28
ft_calloc.c
Executable file
28
ft_calloc.c
Executable file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 17:47:38 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:45:58 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
if (!nmemb || !size)
|
||||
return (malloc(0));
|
||||
if ((nmemb * size) / size != nmemb)
|
||||
return (NULL);
|
||||
ptr = malloc(size * nmemb);
|
||||
if (!ptr)
|
||||
return (0);
|
||||
ft_bzero(ptr, size * nmemb);
|
||||
return (ptr);
|
||||
}
|
||||
21
ft_isalnum.c
Executable file
21
ft_isalnum.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 16:21:11 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 16:24:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
21
ft_isalpha.c
Executable file
21
ft_isalpha.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 13:36:34 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 13:58:21 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
20
ft_isascii.c
Executable file
20
ft_isascii.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 16:40:31 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:07:04 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
21
ft_isdigit.c
Executable file
21
ft_isdigit.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 14:46:59 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 15:55:00 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= 48 && c <= 57)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
20
ft_isprint.c
Executable file
20
ft_isprint.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/03 12:43:03 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/03 13:25:31 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
56
ft_itoa.c
Executable file
56
ft_itoa.c
Executable file
@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 15:53:35 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:21:07 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static size_t ft_len_nb(int nb)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
if (nb <= 0)
|
||||
len++;
|
||||
while (nb)
|
||||
{
|
||||
len++;
|
||||
nb = nb / 10;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
int len;
|
||||
char *str;
|
||||
long nb;
|
||||
|
||||
len = ft_len_nb(n);
|
||||
nb = n;
|
||||
str = malloc(sizeof(char) * len +1);
|
||||
if (!str)
|
||||
return (0);
|
||||
if (nb < 0)
|
||||
{
|
||||
str[0] = '-';
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb == 0)
|
||||
str[0] = '0';
|
||||
str[len--] = '\0';
|
||||
while (nb)
|
||||
{
|
||||
str[len] = nb % 10 + '0';
|
||||
len--;
|
||||
nb = nb / 10;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
29
ft_lstadd_back.c
Executable file
29
ft_lstadd_back.c
Executable file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:08:00 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:15:14 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *temp;
|
||||
|
||||
if (new && lst)
|
||||
{
|
||||
if (*lst)
|
||||
{
|
||||
temp = ft_lstlast(*lst);
|
||||
temp->next = new;
|
||||
}
|
||||
else
|
||||
*lst = new;
|
||||
}
|
||||
}
|
||||
22
ft_lstadd_front.c
Executable file
22
ft_lstadd_front.c
Executable file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/22 18:06:54 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:06:52 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (new)
|
||||
{
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
}
|
||||
25
ft_lstclear.c
Executable file
25
ft_lstclear.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:19:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:22:17 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void*))
|
||||
{
|
||||
t_list *temp;
|
||||
|
||||
while (*lst && lst)
|
||||
{
|
||||
temp = (*lst)->next;
|
||||
ft_lstdelone(*lst, (*del));
|
||||
*lst = temp;
|
||||
}
|
||||
}
|
||||
21
ft_lstdelone.c
Executable file
21
ft_lstdelone.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:17:06 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:33:01 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
24
ft_lstiter.c
Executable file
24
ft_lstiter.c
Executable file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:22:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:24:51 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!lst || !f)
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
24
ft_lstlast.c
Executable file
24
ft_lstlast.c
Executable file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 17:48:29 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:02:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
if (lst->next == NULL)
|
||||
return (lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (lst);
|
||||
}
|
||||
35
ft_lstmap.c
Executable file
35
ft_lstmap.c
Executable file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:25:24 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:29:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *tmp;
|
||||
t_list *res;
|
||||
|
||||
if (!lst || !f)
|
||||
return (NULL);
|
||||
res = 0;
|
||||
while (lst)
|
||||
{
|
||||
tmp = ft_lstnew((*f)(lst->content));
|
||||
if (!tmp)
|
||||
{
|
||||
ft_lstclear(&res, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&res, tmp);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
25
ft_lstnew.c
Executable file
25
ft_lstnew.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/22 17:09:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:06:38 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = malloc(sizeof(t_list));
|
||||
if (!new)
|
||||
return (0);
|
||||
new->content = content;
|
||||
new->next = 0;
|
||||
return (new);
|
||||
}
|
||||
28
ft_lstsize.c
Executable file
28
ft_lstsize.c
Executable file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 17:17:36 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:06:24 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
t_list *tmp;
|
||||
|
||||
tmp = lst;
|
||||
i = 0;
|
||||
while (tmp)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
27
ft_memchr.c
Executable file
27
ft_memchr.c
Executable file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/10 13:42:10 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:03:28 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (((unsigned char *)s)[i] == (unsigned char)c)
|
||||
return ((void *)(s + i));
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
ft_memcmp.c
Executable file
27
ft_memcmp.c
Executable file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/10 14:45:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:18:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
|
||||
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
32
ft_memcpy.c
Executable file
32
ft_memcpy.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/04 14:43:15 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:13:43 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *destmov;
|
||||
char *srcmov;
|
||||
size_t i;
|
||||
|
||||
destmov = (char *)dest;
|
||||
srcmov = (char *)src;
|
||||
if (!dest && !src)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
destmov[i] = srcmov[i];
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
42
ft_memmove.c
Executable file
42
ft_memmove.c
Executable file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/07 11:11:49 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/07 16:04:25 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *destmov;
|
||||
char *srcmov;
|
||||
size_t i;
|
||||
|
||||
if (!dest && !src)
|
||||
return (0);
|
||||
destmov = (char *)dest;
|
||||
srcmov = (char *)src;
|
||||
i = 0;
|
||||
if (destmov > srcmov)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
destmov[n] = srcmov[n];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
destmov[i] = srcmov[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (destmov);
|
||||
}
|
||||
26
ft_memset.c
Executable file
26
ft_memset.c
Executable file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/03 15:49:51 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:07:29 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
*(unsigned char *)(s + i) = (unsigned char)c;
|
||||
i++;
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
18
ft_putchar_fd.c
Executable file
18
ft_putchar_fd.c
Executable file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 11:23:07 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/15 11:30:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
28
ft_putendl_fd.c
Executable file
28
ft_putendl_fd.c
Executable file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 13:33:49 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:19:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!s)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
write(fd, &s[i], 1);
|
||||
i++;
|
||||
}
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
36
ft_putnbr_fd.c
Executable file
36
ft_putnbr_fd.c
Executable file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 13:53:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/15 14:00:06 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
if (n == -2147483648)
|
||||
{
|
||||
write(fd, "-2147483648", 11);
|
||||
}
|
||||
else if (n >= 0 && n < 10)
|
||||
{
|
||||
n += 48;
|
||||
ft_putchar_fd(n, fd);
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
ft_putnbr_fd((n * (-1)), fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putnbr_fd(n / 10, fd);
|
||||
ft_putnbr_fd(n % 10, fd);
|
||||
}
|
||||
}
|
||||
27
ft_putstr_fd.c
Executable file
27
ft_putstr_fd.c
Executable file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 12:29:14 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/15 19:02:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!s || !fd)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
write(fd, &s[i], 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
35
ft_realloc.c
Executable file
35
ft_realloc.c
Executable file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_realloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/15 16:31:35 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/10 13:59:12 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_realloc(void *ptr, size_t newsize, size_t oldsize)
|
||||
{
|
||||
char *newptr;
|
||||
|
||||
if (ptr == NULL)
|
||||
{
|
||||
return (malloc(newsize));
|
||||
}
|
||||
if (newsize <= oldsize)
|
||||
{
|
||||
return (ptr);
|
||||
}
|
||||
newptr = malloc(newsize);
|
||||
if (newptr == NULL)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
ft_memcpy(newptr, ptr, oldsize);
|
||||
free(ptr);
|
||||
return (newptr);
|
||||
}
|
||||
32
ft_reallocarray.c
Executable file
32
ft_reallocarray.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_reallocarray.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/15 15:52:29 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/07 11:46:15 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static size_t get_mul_no_overflow(void)
|
||||
{
|
||||
return ((size_t)1 << (sizeof(size_t) * 4));
|
||||
}
|
||||
|
||||
void *ft_reallocarray(void *optr, size_t nmemb, size_t size, size_t oldsize)
|
||||
{
|
||||
size_t mul_no_overflow;
|
||||
|
||||
mul_no_overflow = get_mul_no_overflow();
|
||||
if ((nmemb >= mul_no_overflow || size >= mul_no_overflow)
|
||||
&& nmemb > 0 && SIZE_MAX / nmemb < size)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (NULL);
|
||||
}
|
||||
return (ft_realloc(optr, nmemb * size, oldsize));
|
||||
}
|
||||
75
ft_split.c
Executable file
75
ft_split.c
Executable file
@ -0,0 +1,75 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 13:12:04 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 11:04:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int count_words(const char *s, char c)
|
||||
{
|
||||
int count;
|
||||
int trigger;
|
||||
|
||||
count = 0;
|
||||
trigger = 0;
|
||||
while (*s)
|
||||
{
|
||||
if (*s != c && trigger == 0)
|
||||
{
|
||||
trigger = 1;
|
||||
count++;
|
||||
}
|
||||
else if (*s == c)
|
||||
trigger = 0;
|
||||
s++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
static char *word_cpy(const char *s, int start, int end)
|
||||
{
|
||||
char *word;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
word = malloc(sizeof(char) * (end - start + 1));
|
||||
while (start < end)
|
||||
word[i++] = s[start++];
|
||||
word[i] = '\0';
|
||||
return (word);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
int index;
|
||||
char **split;
|
||||
|
||||
split = malloc(sizeof(char *) * (count_words(s, c) + 1));
|
||||
if (!s || !split)
|
||||
return (0);
|
||||
i = 0;
|
||||
j = 0;
|
||||
index = -1;
|
||||
while (i <= ft_strlen(s))
|
||||
{
|
||||
if (s[i] != c && index < 0)
|
||||
index = i;
|
||||
else if ((s[i] == c || i == ft_strlen(s)) && index >= 0)
|
||||
{
|
||||
split[j++] = word_cpy(s, index, i);
|
||||
index = -1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
split[j] = 0;
|
||||
return (split);
|
||||
}
|
||||
32
ft_strcat.c
Executable file
32
ft_strcat.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/21 19:20:36 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/21 19:28:29 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcat(char *dest, const char *src)
|
||||
{
|
||||
char *save;
|
||||
|
||||
save = dest;
|
||||
while (*dest)
|
||||
{
|
||||
dest++;
|
||||
}
|
||||
while (*src)
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
*dest = '\0';
|
||||
return (save);
|
||||
}
|
||||
32
ft_strchr.c
Executable file
32
ft_strchr.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 14:27:10 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:54:39 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
str = (char *)s;
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] == (char)c)
|
||||
return (&str[i]);
|
||||
i++;
|
||||
}
|
||||
if (str[i] == (char)c)
|
||||
return (&str[i]);
|
||||
return (0);
|
||||
}
|
||||
23
ft_strcmp.c
Executable file
23
ft_strcmp.c
Executable file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/14 16:57:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:10:27 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 && (*s1 == *s2))
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return (*(const unsigned char *)s1 - *(const unsigned char *)s2);
|
||||
}
|
||||
28
ft_strcpy.c
Executable file
28
ft_strcpy.c
Executable file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/21 19:23:08 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/21 19:26:36 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcpy(char *dest, const char *src)
|
||||
{
|
||||
char *save;
|
||||
|
||||
save = dest;
|
||||
while (*src)
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
*dest = '\0';
|
||||
return (save);
|
||||
}
|
||||
31
ft_strdup.c
Executable file
31
ft_strdup.c
Executable file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 18:40:02 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/10 12:25:07 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
str = (char *)malloc(sizeof(char) * (ft_strlen(s) + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
str[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
str[i] = 0;
|
||||
return (str);
|
||||
}
|
||||
25
ft_striteri.c
Executable file
25
ft_striteri.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 14:25:00 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:08:02 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (!s)
|
||||
return ;
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, &s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
39
ft_strjoin.c
Executable file
39
ft_strjoin.c
Executable file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/13 16:54:51 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/13 13:58:13 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *new_s;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
new_s = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
||||
if (!new_s)
|
||||
return (0);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s1[i])
|
||||
{
|
||||
new_s[j] = s1[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
i = 0;
|
||||
while (s2[i])
|
||||
new_s[j++] = s2[i++];
|
||||
new_s[j] = '\0';
|
||||
return (new_s);
|
||||
}
|
||||
33
ft_strlcat.c
Executable file
33
ft_strlcat.c
Executable file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/08 14:10:58 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:09:41 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t dst_len;
|
||||
|
||||
i = 0;
|
||||
if (!dst && !size)
|
||||
return (0);
|
||||
dst_len = ft_strlen(dst);
|
||||
if (size <= dst_len)
|
||||
return (size + ft_strlen(src));
|
||||
while (src[i] && i < size - dst_len -1)
|
||||
{
|
||||
dst[dst_len + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[dst_len + i] = 0;
|
||||
return (dst_len + ft_strlen(src));
|
||||
}
|
||||
32
ft_strlcpy.c
Executable file
32
ft_strlcpy.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/08 13:24:31 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/08 13:33:32 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (size > 0)
|
||||
{
|
||||
while (src[i] && i < (size - 1))
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[i] = 0;
|
||||
}
|
||||
while (src[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
23
ft_strlen.c
Executable file
23
ft_strlen.c
Executable file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/03 14:10:21 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/03 14:17:21 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
33
ft_strmapi.c
Executable file
33
ft_strmapi.c
Executable file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 13:38:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:04:43 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
char *result;
|
||||
unsigned int i;
|
||||
|
||||
if (!s)
|
||||
return (0);
|
||||
result = malloc(sizeof(char) * (ft_strlen(s) + 1));
|
||||
if (!result)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
result[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
result[i] = 0;
|
||||
return (result);
|
||||
}
|
||||
29
ft_strncmp.c
Executable file
29
ft_strncmp.c
Executable file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 17:12:38 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:26:15 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
while (s1[i] == s2[i] && (s1[i] != '\0' || s2[i] != '\0') && i < (n - 1))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
}
|
||||
31
ft_strncpy.c
Executable file
31
ft_strncpy.c
Executable file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/27 20:03:19 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/07 11:56:51 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0' && i < n)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
++i;
|
||||
}
|
||||
while (i < n)
|
||||
{
|
||||
dest[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
41
ft_strnstr.c
Executable file
41
ft_strnstr.c
Executable file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 14:31:40 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:08:36 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (needle == haystack)
|
||||
return ((char *)haystack);
|
||||
if (!len && !haystack)
|
||||
return (0);
|
||||
while (haystack[i] != '\0')
|
||||
{
|
||||
j = 0;
|
||||
while (haystack[i + j] == needle[j] && (i + j) < len)
|
||||
{
|
||||
if (haystack[i + j] == '\0' && needle[j] == '\0')
|
||||
{
|
||||
return ((char *)&haystack[j]);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (needle[j] == '\0')
|
||||
return ((char *)(haystack + i));
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
29
ft_strrchr.c
Executable file
29
ft_strrchr.c
Executable file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 16:10:11 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 15:36:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
i++;
|
||||
while (i >= 0)
|
||||
{
|
||||
if (s[i] == (char)c)
|
||||
return ((char *)(s + i));
|
||||
i--;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
42
ft_strstr.c
Executable file
42
ft_strstr.c
Executable file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/14 20:54:44 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 21:08:57 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
const char *p;
|
||||
const char *beginning;
|
||||
const char *n;
|
||||
|
||||
p = haystack;
|
||||
if (*needle == '\0')
|
||||
return ((char *)haystack);
|
||||
while (*p != '\0')
|
||||
{
|
||||
if (*p == *needle)
|
||||
{
|
||||
beginning = p;
|
||||
n = needle;
|
||||
while (*p == *n && *n != '\0' && *p != '\0')
|
||||
{
|
||||
p++;
|
||||
n++;
|
||||
}
|
||||
if (*n == '\0')
|
||||
return ((char *)beginning);
|
||||
p = beginning;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
83
ft_strtok.c
Executable file
83
ft_strtok.c
Executable file
@ -0,0 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtok.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/14 17:14:45 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/07 11:41:34 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static char *init_str_and_lasts(char **lasts, char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
{
|
||||
str = *lasts;
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*lasts = str;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
static char *find_token_start(char **lasts, const char *delim)
|
||||
{
|
||||
int ch;
|
||||
|
||||
ch = **lasts;
|
||||
while (ch != '\0' && ft_strchr(delim, ch) != NULL)
|
||||
{
|
||||
(*lasts)++;
|
||||
ch = **lasts;
|
||||
}
|
||||
if (**lasts == '\0')
|
||||
{
|
||||
*lasts = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
return (*lasts);
|
||||
}
|
||||
|
||||
static char *find_token_end(char **lasts, const char *delim)
|
||||
{
|
||||
int ch;
|
||||
char *str;
|
||||
|
||||
str = *lasts;
|
||||
ch = **lasts;
|
||||
while (ch != '\0' && ft_strchr(delim, ch) == NULL)
|
||||
{
|
||||
(*lasts)++;
|
||||
ch = **lasts;
|
||||
}
|
||||
if (**lasts != '\0')
|
||||
{
|
||||
**lasts = '\0';
|
||||
(*lasts)++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*lasts = NULL;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *ft_strtok(char *str, const char *delim)
|
||||
{
|
||||
static char *lasts;
|
||||
|
||||
str = init_str_and_lasts(&lasts, str);
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
str = find_token_start(&lasts, delim);
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
return (find_token_end(&lasts, delim));
|
||||
}
|
||||
115
ft_strtol.c
Executable file
115
ft_strtol.c
Executable file
@ -0,0 +1,115 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtol.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 14:00:32 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/07 11:56:12 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int skip_whitespaces_and_sign(const char *str, int *sign)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
|
||||
i++;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
*sign = -1;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static int determine_base(const char *str, int *base, int index)
|
||||
{
|
||||
if ((*base == 0 || *base == 16) && str[index] == '0'
|
||||
&& (str[index + 1] == 'x' || str[index + 1] == 'X'))
|
||||
{
|
||||
*base = 16;
|
||||
index += 2;
|
||||
}
|
||||
else if (*base == 0)
|
||||
{
|
||||
if (str[index] == '0')
|
||||
*base = 8;
|
||||
else
|
||||
*base = 10;
|
||||
}
|
||||
return (index);
|
||||
}
|
||||
|
||||
static int check_base(const char *str, int *base, int *sign)
|
||||
{
|
||||
int i;
|
||||
|
||||
*sign = 1;
|
||||
i = skip_whitespaces_and_sign(str, sign);
|
||||
i = determine_base(str, base, i);
|
||||
return (i);
|
||||
}
|
||||
|
||||
static long convert_strtol(const char *str, int base, int sign)
|
||||
{
|
||||
long result;
|
||||
int digit;
|
||||
|
||||
result = 0;
|
||||
while (*str)
|
||||
{
|
||||
digit = 0;
|
||||
if (*str >= '0' && *str <= '9')
|
||||
digit = *str - '0';
|
||||
else if (*str >= 'A' && *str <= 'Z')
|
||||
digit = *str - 'A' + 10;
|
||||
else if (*str >= 'a' && *str <= 'z')
|
||||
digit = *str - 'a' + 10;
|
||||
else
|
||||
break ;
|
||||
if (digit >= base)
|
||||
break ;
|
||||
if (sign > 0 && result > (LONG_MAX - digit) / base)
|
||||
return (errno = ERANGE, LONG_MAX);
|
||||
if (sign < 0 && result < (LONG_MIN + digit) / base)
|
||||
return (errno = ERANGE, LONG_MIN);
|
||||
result = result * base + digit;
|
||||
str++;
|
||||
}
|
||||
return (result * sign);
|
||||
}
|
||||
|
||||
long ft_strtol(const char *str, char **endptr, int base)
|
||||
{
|
||||
int sign;
|
||||
int i;
|
||||
long result;
|
||||
|
||||
if (base < 0 || base == 1 || base > 36)
|
||||
{
|
||||
if (endptr)
|
||||
*endptr = (char *)str;
|
||||
return (0);
|
||||
}
|
||||
i = check_base(str, &base, &sign);
|
||||
result = convert_strtol(str + i, base, sign);
|
||||
if (endptr)
|
||||
*endptr = (char *)(str + i);
|
||||
while (*str)
|
||||
{
|
||||
if ((*str >= '0' && *str <= '9' && *str - '0' < base)
|
||||
|| (*str >= 'A' && *str <= 'Z' && *str - 'A' + 10 < base)
|
||||
|| (*str >= 'a' && *str <= 'z' && *str - 'a' + 10 < base))
|
||||
*endptr = (char *)(str + 1);
|
||||
else
|
||||
break ;
|
||||
str++;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
52
ft_strtrim.c
Executable file
52
ft_strtrim.c
Executable file
@ -0,0 +1,52 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/14 16:30:26 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/13 14:12:41 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int char_in_set(char c, char const *set)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (set[i])
|
||||
{
|
||||
if (set[i] == c)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
size_t start;
|
||||
size_t end;
|
||||
|
||||
if (!s1)
|
||||
return (0);
|
||||
start = 0;
|
||||
while (s1[start] && char_in_set(s1[start], set))
|
||||
start++;
|
||||
end = ft_strlen(s1);
|
||||
while (end > start && char_in_set(s1[end - 1], set))
|
||||
end--;
|
||||
str = (char *)malloc(sizeof(*s1) * (end - start + 1));
|
||||
if (!str)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (start < end)
|
||||
str[i++] = s1[start++];
|
||||
str[i] = 0;
|
||||
return (str);
|
||||
}
|
||||
37
ft_substr.c
Executable file
37
ft_substr.c
Executable file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/13 15:40:49 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/11/14 17:07:20 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *new_s;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
new_s = (char *)malloc(sizeof(char) * (len + 1));
|
||||
if (!s || !new_s)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (i >= start && j < len)
|
||||
{
|
||||
new_s[j] = s[i];
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
new_s[j] = '\0';
|
||||
return (new_s);
|
||||
}
|
||||
20
ft_tolower.c
Executable file
20
ft_tolower.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 14:09:59 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:36:02 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 65 && c <= 90)
|
||||
c += 32;
|
||||
return (c);
|
||||
}
|
||||
20
ft_toupper.c
Executable file
20
ft_toupper.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/08 16:02:00 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:36:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 97 && c <= 122)
|
||||
c -= 32;
|
||||
return (c);
|
||||
}
|
||||
85
libft.h
Executable file
85
libft.h
Executable file
@ -0,0 +1,85 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/12 10:46:53 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/07 11:47:27 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
# include <sys/types.h>
|
||||
# include <errno.h>
|
||||
# include <stdint.h>
|
||||
# include <limits.h>
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
int ft_atoi(const char *nptr);
|
||||
int ft_lstsize(t_list *lst);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void ft_bzero(void *ptr, size_t len);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
size_t ft_strlen(const char *s);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strtok(char *str, const char *delim);
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
|
||||
char *ft_strdup(const char *s);
|
||||
char *ft_strstr(const char *haystack, const char *needle);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
|
||||
char *ft_strncpy(char *dest, char *src, unsigned int n);
|
||||
char **ft_split(char const *s, char c);
|
||||
void *ft_reallocarray(void *optr, size_t nmemb, size_t size, size_t oldsize);
|
||||
void *ft_realloc(void *ptr, size_t newsize, size_t oldsize);
|
||||
char *ft_itoa(int n);
|
||||
char *ft_strcat(char *dest, const char *src);
|
||||
char *ft_strcpy(char *dest, const char *src);
|
||||
t_list *ft_lstnew(void *content);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
long ft_strtol(const char *str, char **endptr, int base);
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user