Firstcommit
This commit is contained in:
commit
8eea3162d5
|
|
@ -0,0 +1,46 @@
|
|||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
NAME = cub3d
|
||||
|
||||
SRCDIR = srcs
|
||||
INCDIR = includes
|
||||
LIBFT = libft/libft.a
|
||||
GNL = gnl/gnl.a
|
||||
|
||||
SRCS = $(SRCDIR)/main.c \
|
||||
$(SRCDIR)/parsing/parsing.c \
|
||||
$(SRCDIR)/parsing/check_file.c \
|
||||
$(SRCDIR)/parsing/init_parsing.c \
|
||||
$(SRCDIR)/parsing/get_map.c \
|
||||
$(SRCDIR)/parsing/line_detect.c \
|
||||
$(SRCDIR)/parsing/get_textures.c \
|
||||
$(SRCDIR)/parsing/check_colors.c \
|
||||
$(SRCDIR)/utils/utils.c \
|
||||
$(SRCDIR)/utils/init.c \
|
||||
$(SRCDIR)/utils/debug.c \
|
||||
|
||||
INCS = $(INCDIR)/parsing.h \
|
||||
$(INCDIR)/cub.h \
|
||||
$(INCDIR)/messages.h \
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(SRCS) $(INCS)
|
||||
@$(MAKE) -s -C libft
|
||||
@$(MAKE) -s -C gnl
|
||||
$(CC) -g -I$(INCDIR) $(SRCS) -o $(NAME) $(LIBFT) $(GNL)
|
||||
|
||||
clean:
|
||||
rm -f $(NAME)
|
||||
@make clean -s -C libft
|
||||
@make clean -s -C gnl
|
||||
|
||||
clean1:
|
||||
rm -f $(NAME)
|
||||
|
||||
fclean: clean1
|
||||
@make fclean -s -C libft
|
||||
@make fclean -s -C gnl
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re clean1
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: lfirmin lfirmim@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/08/12 07:07:31 by lfirmin #+# #+# #
|
||||
# Updated: 2024/08/12 09:15:05 by lfirmin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = gnl.a
|
||||
SRCS_DIR = srcs/
|
||||
INCS_DIR = includes/
|
||||
OBJ_DIR = obj/
|
||||
|
||||
SRC = get_next_line.c get_next_line_utils.c
|
||||
|
||||
CC = cc
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
INCLUDE = -I $(INCS_DIR)
|
||||
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
||||
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
||||
|
||||
# Colors
|
||||
GREEN = \033[0;32m
|
||||
YELLOW = \033[0;33m
|
||||
RESET = \033[0m
|
||||
WHITE = \033[0;97m
|
||||
|
||||
# Loading animation
|
||||
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
@printf "$(YELLOW)Compiling get_next_line, Please wait...$(RESET)"
|
||||
@for char in $(LOADING_CHARS); do \
|
||||
printf "\r$(YELLOW)Compiling get_next_line, Please wait... $$char$(RESET)"; \
|
||||
sleep 0.1; \
|
||||
done
|
||||
@ar rc $(NAME) $(OBJ)
|
||||
@ranlib $(NAME)
|
||||
@printf "\r$(GREEN)fine ! $(WHITE)get_next_line compiled successfully ! $(RESET)\n"
|
||||
|
||||
$(OBJ_DIR)%.o: $(SRCS_DIR)%.c
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ_DIR)
|
||||
@printf "$(WHITE)Clean process completed for $(GREEN)get_next_line.$(RESET)\n"
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
@printf "$(WHITE)Full clean process completed for $(GREEN)get_next_line.$(RESET)\n"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/21 19:32:47 by abelghou #+# #+# */
|
||||
/* Updated: 2024/07/23 20:47:15 by abelghou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GET_NEXT_LINE_H
|
||||
# define GET_NEXT_LINE_H
|
||||
|
||||
# ifndef BUFFER_SIZE
|
||||
# define BUFFER_SIZE 1000
|
||||
# endif
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <stdio.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
int ft_strlen_g(const char *str);
|
||||
char *ft_strchr_gnl(const char *s, int i);
|
||||
char *ft_strdup_g(const char *s);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *get_next_line(int fd);
|
||||
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,41 @@
|
|||
# get_next_line
|
||||
|
||||
A function that reads a line from a file descriptor.
|
||||
|
||||
## 💡 About
|
||||
The get_next_line project is a programming function that reads a line ending with a newline character from a file descriptor. When calling the function in a loop, it will then allow you to read the text file pointed to by the file descriptor, one line at a time until the end of the file.
|
||||
|
||||
## 🛠️ Function Prototype
|
||||
```c
|
||||
char *get_next_line(int fd);
|
||||
```
|
||||
## 📋 Usage
|
||||
```c
|
||||
#include "get_next_line.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd;
|
||||
char *line;
|
||||
|
||||
fd = open("test.txt", O_RDONLY);
|
||||
while ((line = get_next_line(fd)) != NULL)
|
||||
{
|
||||
printf("%s", line);
|
||||
free(line);
|
||||
}
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
||||
```
|
||||
|
||||
## ⚠️ Return Value
|
||||
* The line that was read when successful
|
||||
* NULL if there is nothing else to read or if an error occurred
|
||||
|
||||
## 📊 Expected Behavior
|
||||
* Repeated calls to get_next_line() should let you read the text file pointed to by the file descriptor, one line at a time
|
||||
* The function should return the line that was read
|
||||
* If there is nothing else to read or if an error occurred, it should return NULL
|
||||
* The returned line should include the terminating \n character, except if the end of file was reached and does not end with a \n character
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/17 21:31:24 by abelghou #+# #+# */
|
||||
/* Updated: 2024/07/24 18:17:55 by abelghou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../include/get_next_line.h"
|
||||
|
||||
static char *sort_and_store(int fd, char *buf, char *backup)
|
||||
{
|
||||
int read_line;
|
||||
char *char_temp;
|
||||
|
||||
read_line = 1;
|
||||
while (read_line != 0)
|
||||
{
|
||||
read_line = read(fd, buf, BUFFER_SIZE);
|
||||
if (read_line == -1)
|
||||
return (0);
|
||||
else if (read_line == 0)
|
||||
break ;
|
||||
buf[read_line] = '\0';
|
||||
if (!backup)
|
||||
backup = ft_strdup_g("");
|
||||
if (!backup)
|
||||
return (NULL);
|
||||
char_temp = backup;
|
||||
backup = ft_strjoin(char_temp, buf);
|
||||
free(char_temp);
|
||||
char_temp = NULL;
|
||||
if (ft_strchr_gnl (buf, '\n'))
|
||||
break ;
|
||||
}
|
||||
return (backup);
|
||||
}
|
||||
|
||||
static char *extract(char *line)
|
||||
{
|
||||
size_t count;
|
||||
char *backup;
|
||||
|
||||
count = 0;
|
||||
while (line[count] != '\n' && line[count] != '\0')
|
||||
count++;
|
||||
if (line[count] == '\0' || line[1] == '\0')
|
||||
return (0);
|
||||
backup = ft_substr(line, count + 1, ft_strlen_g(line) - count);
|
||||
if (!backup)
|
||||
return (NULL);
|
||||
if (*backup == '\0')
|
||||
{
|
||||
free (backup);
|
||||
backup = NULL;
|
||||
}
|
||||
line[count + 1] = '\0';
|
||||
return (backup);
|
||||
}
|
||||
|
||||
char *get_next_line(int fd)
|
||||
{
|
||||
char *line;
|
||||
char *buf;
|
||||
char *temp;
|
||||
static char *backup;
|
||||
|
||||
if (fd < 0 || BUFFER_SIZE <= 0)
|
||||
return (free(backup), backup = NULL, NULL);
|
||||
buf = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1));
|
||||
if (!buf)
|
||||
return (free(backup), backup = NULL, NULL);
|
||||
line = sort_and_store(fd, buf, backup);
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
if (!line)
|
||||
return (free(backup), backup = NULL, NULL);
|
||||
backup = extract(line);
|
||||
temp = ft_strdup_g(line);
|
||||
free(line);
|
||||
if (!temp)
|
||||
return (free(backup), backup = NULL, NULL);
|
||||
return (temp);
|
||||
}
|
||||
|
||||
// int main()
|
||||
// {
|
||||
// int fd;
|
||||
// char *line;
|
||||
// fd = open("fd.txt", O_RDONLY);
|
||||
// while((line = get_next_line(fd)) != NULL)
|
||||
// {
|
||||
// printf("%s", line);
|
||||
// free(line);
|
||||
// }
|
||||
// line = get_next_line(fd);
|
||||
// close(fd);
|
||||
// }
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/21 19:34:18 by abelghou #+# #+# */
|
||||
/* Updated: 2024/07/23 20:06:41 by abelghou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../include/get_next_line.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
char *str;
|
||||
|
||||
str = (char *)malloc(sizeof(*s) * (len + 1));
|
||||
if (str == 0)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (i >= start && j < len)
|
||||
{
|
||||
str[j] = s[i];
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
str[j] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
int ft_strlen_g(const char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strchr_gnl(const char *s, int i)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
if (*s == i)
|
||||
return ((char *)s);
|
||||
s++;
|
||||
}
|
||||
if (i == '\0')
|
||||
return ((char *)s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *ft_strdup_g(const char *s)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
j = ft_strlen_g(s);
|
||||
str = (char *)malloc(sizeof(*str) * (j + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (i < j)
|
||||
{
|
||||
str[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
str = (char *)malloc(sizeof(char) * (ft_strlen_g(s1) \
|
||||
+ ft_strlen_g(s2) + 1));
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
str[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
while (s2[j] != '\0')
|
||||
{
|
||||
str[i + j] = s2[j];
|
||||
j++;
|
||||
}
|
||||
str[i + j] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
#ifndef CUB_H
|
||||
#define CUB_H
|
||||
|
||||
#include "parsing.h"
|
||||
#include "messages.h"
|
||||
#include "../libft/include/libft.h"
|
||||
#include "../gnl/include/get_next_line.h"
|
||||
|
||||
typedef struct s_data
|
||||
{
|
||||
char **map;
|
||||
char *map_path;
|
||||
t_textures *texture;
|
||||
t_data_parsing parsing;
|
||||
} t_data;
|
||||
|
||||
//////utils/////
|
||||
//utils
|
||||
void ft_error(char *message);
|
||||
void free_char_array(char **array);
|
||||
//init
|
||||
int init_data(t_data *data, char *path);
|
||||
void free_data(t_data *data);
|
||||
|
||||
/////debug
|
||||
void print_char_array_debug(char **arr, char *name);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* messages.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 15:00:45 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/08/22 15:01:20 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#define ERROR_PREFIX "\033[1m[❌]\033[0m\033[1;31mError\033[0m: "
|
||||
#define ERROR_EXT "Invalid file extension. Only .cub files are accepted."
|
||||
#define ERROR_EMPT_PATH "Invalid map file path."
|
||||
#define ERROR_INIT_DATA "Initialization of the data structure failed."
|
||||
#define ERROR_INIT_TEX "Initialization of the textures structure failed."
|
||||
#define ERROR_INIT_PARS "Initialization of the parsing structure failed."
|
||||
#define ERROR_EMPTY "You have provided an empty file."
|
||||
#define ERROR_COL "The RGB values provided are not valid."
|
||||
|
||||
#define DEBUG "test"
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 14:08:04 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/08/22 14:18:06 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSING_H
|
||||
#define PARSING_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
struct s_data;
|
||||
typedef struct s_data t_data;
|
||||
|
||||
typedef struct s_textures
|
||||
{
|
||||
char *north; //Path to texture.xmp
|
||||
char *south; //Path to texture.xmp
|
||||
char *east; //Path to texture.xmp
|
||||
char *west; //Path to texture.xmp
|
||||
int floor[3]; //RGB: [0] = R, [1] = G, [2] = B
|
||||
int ceiling[3]; //RGB: [0] = R, [1] = G, [2] = B
|
||||
} t_textures;
|
||||
|
||||
typedef struct s_data_parsing
|
||||
{
|
||||
char **raw_map;
|
||||
int fd_map;
|
||||
int fd_map_dup;
|
||||
} t_data_parsing;
|
||||
|
||||
//parsing
|
||||
int parsing(t_data *data);
|
||||
|
||||
//check_file
|
||||
int check_extension(char *map_path);
|
||||
int check_file(char *map_path, t_data_parsing *parsing);
|
||||
|
||||
//get_map
|
||||
int get_map(t_data *data);
|
||||
int line_counter(int fd);
|
||||
int put_map_on_array(t_data *data);
|
||||
char *clean_line(char *raw_line);
|
||||
|
||||
//init_parsing
|
||||
int init_parsing(t_data_parsing *parsing);
|
||||
int init_textures(t_textures *textures);
|
||||
int free_textures(t_textures *textures);
|
||||
|
||||
//line_detect
|
||||
int is_config_line(char *line);
|
||||
int is_empty_line(char *line);
|
||||
int is_texture_line(char *line);
|
||||
int is_color_line(char *line);
|
||||
|
||||
//get_textures
|
||||
int get_texture_path(char *line, t_textures *texture);
|
||||
int get_rgb_values(char *line, int rgb[3]);
|
||||
|
||||
//check_colors
|
||||
int check_colors(t_textures *texture);
|
||||
int is_rgb(int color[3]);
|
||||
#endif
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/05/19 12:59:31 by lfirmin #+# #+# #
|
||||
# Updated: 2025/04/19 11:53:48 by lfirmin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
HEADER = ./include
|
||||
SRCS_DIR = ./srcs/
|
||||
SRC = ft_isalnum.c ft_isprint.c ft_memcmp.c ft_putchar_fd.c ft_split.c \
|
||||
ft_strlcat.c ft_strncmp.c ft_substr.c ft_atoi.c ft_isalpha.c \
|
||||
ft_itoa.c ft_memcpy.c ft_putendl_fd.c ft_strchr.c ft_strlcpy.c \
|
||||
ft_strnstr.c ft_tolower.c ft_bzero.c ft_isascii.c ft_strtrim.c \
|
||||
ft_memmove.c ft_putnbr_fd.c ft_strdup.c ft_strlen.c ft_strrchr.c \
|
||||
ft_toupper.c ft_calloc.c ft_isdigit.c ft_memchr.c ft_memset.c \
|
||||
ft_putstr_fd.c ft_strjoin.c ft_strmapi.c ft_striteri.c \
|
||||
ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
|
||||
ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \
|
||||
ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c ft_strcmp.c \
|
||||
ft_atoll.c ft_straddchar.c ft_strcpy.c
|
||||
|
||||
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
||||
CC = cc
|
||||
CFLAGS = -Wall -Wextra -Werror -g3
|
||||
INCLUDE = -I $(HEADER)
|
||||
OBJ_DIR = obj/
|
||||
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
||||
|
||||
GREEN = \033[0;32m
|
||||
YELLOW = \033[0;33m
|
||||
RESET = \033[0m
|
||||
WHITE = \033[0;97m
|
||||
|
||||
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
@printf "$(YELLOW)Compiling libft, Please wait...$(RESET)"
|
||||
@for char in $(LOADING_CHARS); do \
|
||||
printf "\r$(YELLOW)Compiling libft, Please wait... $$char$(RESET)"; \
|
||||
sleep 0.1; \
|
||||
done
|
||||
@ar rc $(NAME) $(OBJ)
|
||||
@ranlib $(NAME)
|
||||
@printf "\r$(GREEN)Great news ! $(WHITE)Libft compiled successfully ! $(RESET)\n"
|
||||
|
||||
$(OBJ_DIR)%.o: $(SRCS_DIR)%.c
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ_DIR)
|
||||
@printf "$(WHITE)Clean process completed for $(GREEN)Libft.$(RESET)\n"
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
@printf "$(WHITE)Full clean process completed for $(GREEN)Libft.$(RESET)\n"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
# Libft - 42 Project
|
||||
|
||||
## Description
|
||||
Libft is the first project at 42 school. The aim is to recreate various standard C library functions, as well as additional functions that will be useful throughout the cursus. This library will be used in most of the future 42 projects.
|
||||
|
||||
## Functions
|
||||
|
||||
### Libc Functions
|
||||
`ft_isalpha` • `ft_isdigit` • `ft_isalnum` • `ft_isascii` • `ft_isprint` • `ft_strlen` • `ft_memset` • `ft_bzero` • `ft_memcpy` • `ft_memmove` • `ft_strlcpy` • `ft_strlcat` • `ft_toupper` • `ft_tolower` • `ft_strchr` • `ft_strrchr` • `ft_strncmp` • `ft_memchr` • `ft_memcmp` • `ft_strnstr` • `ft_atoi` • `ft_calloc` • `ft_strdup`
|
||||
|
||||
### Additional Functions
|
||||
`ft_substr` • `ft_strjoin` • `ft_strtrim` • `ft_split` • `ft_itoa` • `ft_strmapi` • `ft_striteri` • `ft_putchar_fd` • `ft_putstr_fd` • `ft_putendl_fd` • `ft_putnbr_fd`
|
||||
|
||||
### Bonus Functions
|
||||
`ft_lstnew` • `ft_lstadd_front` • `ft_lstsize` • `ft_lstlast` • `ft_lstadd_back` • `ft_lstdelone` • `ft_lstclear` • `ft_lstiter` • `ft_lstmap`
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
- GCC compiler
|
||||
- Make
|
||||
|
||||
### Usage
|
||||
1. Include the header in your source file:
|
||||
```c
|
||||
#include "libft.h"
|
||||
```
|
||||
|
||||
### Compilation
|
||||
1. Compilation:
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
## Cleaning
|
||||
- Remove object files:
|
||||
```bash
|
||||
make clean
|
||||
```
|
||||
|
||||
- Remove object files and library:
|
||||
```bash
|
||||
make fclean
|
||||
```
|
||||
|
||||
- Recompile everything:
|
||||
```bash
|
||||
make re
|
||||
```
|
||||
|
||||
## Testing
|
||||
This project doesn't come with unit tests, but you can use external testers:
|
||||
- [libft-unit-test](https://github.com/alelievr/libft-unit-test)
|
||||
- [libft-war-machine](https://github.com/ska42/libft-war-machine)
|
||||
- [Tripouille/libfTester](https://github.com/Tripouille/libftTester)
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 11:19:08 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/04/19 11:56:03 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <stddef.h>
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
# include <limits.h>
|
||||
|
||||
typedef struct v
|
||||
{
|
||||
char **array;
|
||||
int i;
|
||||
int j;
|
||||
int start;
|
||||
int end;
|
||||
} t_split_struct;
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
int ft_isalnum(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_atoi(const char *str);
|
||||
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num);
|
||||
int ft_strncmp(const char *s1, const char *s2, unsigned int n);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_lstsize(t_list *lst);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
long long ft_atoll(const char *str);
|
||||
|
||||
size_t ft_strlen(const char *s);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t dsts);
|
||||
|
||||
void *ft_bzero(void *s, size_t n);
|
||||
void *ft_calloc(size_t count, size_t n);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t len);
|
||||
void *ft_memset(void *b, int c, size_t len);
|
||||
void *ft_memmove(void *s1, const void *s2, size_t len);
|
||||
void *ft_memset(void *str, int c, size_t n);
|
||||
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 *));
|
||||
|
||||
char *ft_strchr(char const *str, int c);
|
||||
char *ft_strdup(const char *src);
|
||||
char *ft_strjoin(const char *s1, const char *s2);
|
||||
char *ft_strnstr(const char *hay, const char *need, size_t len);
|
||||
char *ft_strrchr(const char *str, int c);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
char *ft_itoa(int n);
|
||||
char *ft_straddchar(char *str, char c);
|
||||
char *ft_strcpy(char *dest, 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 *));
|
||||
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 10:09:46 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/03 21:02:02 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int i;
|
||||
int s;
|
||||
int m;
|
||||
|
||||
i = 0;
|
||||
s = 0;
|
||||
m = 0;
|
||||
while ((str[i] <= 13 && str[i] >= 9) || str[i] == 32)
|
||||
i++;
|
||||
while (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
s++;
|
||||
if (s >= 2)
|
||||
return (0);
|
||||
if (str[i] == '-')
|
||||
m++;
|
||||
i++;
|
||||
}
|
||||
s = 0;
|
||||
while (str[i] >= 48 && str[i] <= 57)
|
||||
s = s * 10 + (str[i++] - 48);
|
||||
if (m % 2 == 1)
|
||||
s = s * -1;
|
||||
return (s);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoll.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/03 17:25:06 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/11/03 17:25:33 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
long long ft_atoll(const char *str)
|
||||
{
|
||||
long long result;
|
||||
int sign;
|
||||
|
||||
result = 0;
|
||||
sign = 1;
|
||||
while (*str == ' ' || (*str >= 9 && *str <= 13))
|
||||
str++;
|
||||
if (*str == '-' || *str == '+')
|
||||
{
|
||||
if (*str == '-')
|
||||
sign = -1;
|
||||
str++;
|
||||
}
|
||||
while (*str >= '0' && *str <= '9')
|
||||
{
|
||||
if (result > INT_MAX || result < INT_MIN)
|
||||
return (2147483648);
|
||||
result = result * 10 + (*str - '0');
|
||||
str++;
|
||||
}
|
||||
return (result * sign);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 00:20:00 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/30 19:49:23 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_bzero(void *b, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *r;
|
||||
|
||||
r = (unsigned char *)b;
|
||||
i = 0;
|
||||
while (i < len)
|
||||
r[i++] = '\0';
|
||||
return (b);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 11:14:02 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/03 18:15:05 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t c, size_t s)
|
||||
{
|
||||
void *ptr;
|
||||
long long int tmp1;
|
||||
long long int tmp2;
|
||||
|
||||
tmp1 = (long long int)c;
|
||||
tmp2 = (long long int)s;
|
||||
if ((c > 4294967295 || s > 4294967295) && (tmp1 < 0 && tmp2 < 0))
|
||||
return (NULL);
|
||||
if (tmp1 * tmp2 < 0)
|
||||
return (NULL);
|
||||
ptr = malloc(c * s);
|
||||
if (!ptr)
|
||||
return (NULL);
|
||||
ft_bzero(ptr, c * s);
|
||||
return (ptr);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 02:29:49 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if ((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c >= 65 && c <= 90))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 01:55:52 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 02:36:17 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 02:31:51 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= 48 && c <= 57)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 02:38:24 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/23 06:21:54 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (((c >= 0 && c <= 31) || c >= 127 || c == EOF))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/24 12:59:00 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/29 10:31:36 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
static size_t ft_count(long int n)
|
||||
{
|
||||
size_t c;
|
||||
|
||||
c = 0;
|
||||
if (n <= 0)
|
||||
c = 1;
|
||||
while (n != 0)
|
||||
{
|
||||
n = n / 10;
|
||||
c++;
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *str;
|
||||
size_t size;
|
||||
long int num;
|
||||
|
||||
num = n;
|
||||
size = ft_count(num);
|
||||
str = (char *)malloc(size + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
str[size] = '\0';
|
||||
if (num < 0)
|
||||
num = -num;
|
||||
while (size--)
|
||||
{
|
||||
str[size] = num % 10 + '0';
|
||||
num = num / 10;
|
||||
if (n < 0 && size == 0)
|
||||
str[size] = '-';
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 02:01:18 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/03 15:59:33 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *last;
|
||||
|
||||
if (!new)
|
||||
return ;
|
||||
if (!lst || !*lst)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
last = ft_lstlast(*lst);
|
||||
last->next = new;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/31 20:34:57 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/31 20:41:34 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (lst && new)
|
||||
{
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 20:46:07 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/01 20:51:07 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void*))
|
||||
{
|
||||
t_list *t;
|
||||
|
||||
if (lst)
|
||||
{
|
||||
while (*lst)
|
||||
{
|
||||
t = (*lst)->next;
|
||||
ft_lstdelone(*lst, del);
|
||||
(*lst) = t;
|
||||
}
|
||||
(*lst) = NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 20:32:56 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/01 20:32:56 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 21:05:12 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/01 21:05:12 by lfirmin ### ########.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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 01:52:09 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/01 01:57:22 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
if (!lst->next)
|
||||
return (lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (lst);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/02 18:21:09 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/03 15:53:13 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *new;
|
||||
t_list *save;
|
||||
|
||||
if (!lst || !del || !f)
|
||||
return (NULL);
|
||||
new = ft_lstnew(lst->content);
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new->content = f(new->content);
|
||||
save = new;
|
||||
lst = lst->next;
|
||||
while (lst)
|
||||
{
|
||||
new->next = ft_lstnew(lst->content);
|
||||
if (!new->next)
|
||||
{
|
||||
ft_lstclear(&save, del);
|
||||
return (NULL);
|
||||
}
|
||||
new->next->content = f(new->next->content);
|
||||
new = new->next;
|
||||
lst = lst->next;
|
||||
}
|
||||
new->next = NULL;
|
||||
return (save);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/31 18:41:23 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/31 20:33:26 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = (t_list *)malloc(sizeof(*new));
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new->content = content;
|
||||
new->next = NULL;
|
||||
return (new);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/31 22:00:49 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/31 22:12:17 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
t_list *count;
|
||||
|
||||
count = lst;
|
||||
i = 0;
|
||||
while (count)
|
||||
{
|
||||
count = count->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 07:40:39 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *str;
|
||||
|
||||
str = (unsigned char *)s;
|
||||
while (n--)
|
||||
{
|
||||
if (*str == (unsigned char)c)
|
||||
return (str);
|
||||
str++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 07:57:58 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 11:34:35 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num)
|
||||
{
|
||||
unsigned char *pt1;
|
||||
unsigned char *pt2;
|
||||
size_t i;
|
||||
|
||||
pt1 = (unsigned char *)ptr1;
|
||||
pt2 = (unsigned char *)ptr2;
|
||||
i = 0;
|
||||
while (i < num)
|
||||
{
|
||||
if (pt1[i] != pt2[i])
|
||||
return (pt1[i] - pt2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tordner <tordner@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 01:08:31 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/06/02 00:40:39 by tordner ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *r;
|
||||
unsigned char *s;
|
||||
|
||||
i = 0;
|
||||
r = (unsigned char *)dest;
|
||||
s = (unsigned char *)src;
|
||||
if (dest == (void *)0 && src == (void *)0)
|
||||
return (dest);
|
||||
while (i < len)
|
||||
{
|
||||
r[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmov.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 01:26:13 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *s1, const void *s2, size_t len)
|
||||
{
|
||||
unsigned char *dest;
|
||||
unsigned char *src;
|
||||
unsigned int i;
|
||||
|
||||
dest = (unsigned char *)s1;
|
||||
src = (unsigned char *)s2;
|
||||
i = 0;
|
||||
if (dest == NULL && src == NULL)
|
||||
return (NULL);
|
||||
if (dest < src)
|
||||
{
|
||||
while (i < len)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (0 < len--)
|
||||
dest[len] = src[len];
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 02:42:40 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *r;
|
||||
|
||||
i = 0;
|
||||
r = (unsigned char *)b;
|
||||
while (i < len)
|
||||
r[i++] = (unsigned char)c;
|
||||
return (b);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 11:17:45 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/29 11:20:42 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 11:35:44 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/29 11:38:36 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 11:42:38 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/29 11:56:04 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
long int nb;
|
||||
|
||||
nb = n;
|
||||
if (nb < 0)
|
||||
{
|
||||
nb = -nb;
|
||||
ft_putchar_fd('-', fd);
|
||||
}
|
||||
if (nb >= 10)
|
||||
{
|
||||
ft_putnbr_fd(nb / 10, fd);
|
||||
ft_putnbr_fd(nb % 10, fd);
|
||||
}
|
||||
else
|
||||
ft_putchar_fd(nb + '0', fd);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 11:27:05 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/29 11:33:18 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
ft_putchar_fd(s[i], fd);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/22 05:56:37 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/06/04 12:08:51 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_c(char const *s, char c)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] != c && (i == 0 || s[i - 1] == c))
|
||||
count++;
|
||||
i++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
void init_split_struct(t_split_struct *v, char const *s, char c)
|
||||
{
|
||||
if (!s)
|
||||
return ;
|
||||
v->array = (char **)malloc((ft_c(s, c) + 1) * sizeof(char *));
|
||||
if (!s || !v->array)
|
||||
return ;
|
||||
v->i = 0;
|
||||
v->j = 0;
|
||||
}
|
||||
|
||||
static char *ft_strncpy(char *dest, const 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);
|
||||
}
|
||||
|
||||
char **free_split(char **array, size_t j)
|
||||
{
|
||||
while (j > 0)
|
||||
{
|
||||
free(array[--j]);
|
||||
}
|
||||
free(array);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
t_split_struct v;
|
||||
|
||||
init_split_struct(&v, s, c);
|
||||
if (!s || !v.array)
|
||||
return (NULL);
|
||||
while (s[v.i])
|
||||
{
|
||||
while (s[v.i] == c && s[v.i])
|
||||
v.i++;
|
||||
v.start = v.i;
|
||||
while (s[v.i] != c && s[v.i])
|
||||
v.i++;
|
||||
if (v.i > v.start)
|
||||
{
|
||||
v.array[v.j] = (char *)malloc(v.i - v.start + 1);
|
||||
if (!v.array[v.j])
|
||||
return (free_split(v.array, v.j));
|
||||
ft_strncpy(v.array[v.j], &s[v.start], v.i - v.start);
|
||||
v.array[v.j][v.i - v.start] = '\0';
|
||||
v.j++;
|
||||
}
|
||||
}
|
||||
v.array[v.j] = NULL;
|
||||
return (v.array);
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_straddchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/08 06:02:17 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/11/08 06:02:17 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_straddchar(char *str, char c)
|
||||
{
|
||||
int i;
|
||||
char *res;
|
||||
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
res = (char *)malloc(sizeof(char) * (i + 2));
|
||||
if (!res)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
res[i] = str[i];
|
||||
i++;
|
||||
}
|
||||
res[i] = c;
|
||||
res[i + 1] = '\0';
|
||||
return (res);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 06:46:40 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/24 08:51:25 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(char const *str, int c)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (*str == (char)c)
|
||||
return ((char *)str);
|
||||
str++;
|
||||
}
|
||||
if (*str == (char)c)
|
||||
return ((char *)str);
|
||||
else
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/19 21:01:26 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/10/19 21:01:26 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
|
||||
i++;
|
||||
return (s1[i] - s2[i]);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/19 11:53:24 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/04/19 11:58:04 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcpy(char *dest, char *src)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 05:28:24 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *src)
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
int size;
|
||||
|
||||
size = 0;
|
||||
while (src[size] != '\0')
|
||||
size++;
|
||||
dest = malloc(sizeof(char) * (size + 1));
|
||||
if (dest == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i != size)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 10:54:40 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/29 11:12:05 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (s)
|
||||
{
|
||||
while (s[i])
|
||||
{
|
||||
f(i, &s[i]);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/22 01:00:14 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/05/24 08:49:06 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(const char *s1, const char *s2)
|
||||
{
|
||||
char *res;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (s1 == NULL && s2 == NULL)
|
||||
return (NULL);
|
||||
res = (char *) malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
|
||||
if (!res)
|
||||
return (NULL);
|
||||
while (s1[i])
|
||||
res[j++] = s1[i++];
|
||||
i = 0;
|
||||
while (s2[i])
|
||||
res[j++] = s2[i++];
|
||||
res[j] = 0;
|
||||
return (res);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue