Skip to content

Commit 8b5aa21

Browse files
authored
Add files via upload
1 parent 0c3a5b1 commit 8b5aa21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1377
-0
lines changed

libft/Makefile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: mjuicha <[email protected]> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2023/11/12 14:45:23 by mjuicha #+# #+# #
9+
# Updated: 2023/12/08 10:58:48 by mjuicha ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
SRCS = ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c \
14+
ft_isprint.c ft_strlen.c ft_memset.c ft_bzero.c ft_memcpy.c \
15+
ft_memmove.c ft_strlcpy.c ft_strlcat.c ft_toupper.c ft_tolower.c \
16+
ft_strchr.c ft_strrchr.c ft_strncmp.c ft_memchr.c ft_memcmp.c ft_strnstr.c \
17+
ft_atoi.c ft_calloc.c ft_strdup.c ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c \
18+
ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c
19+
20+
SRCB = ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
21+
ft_lstlast_bonus.c ft_lstadd_back_bonus.c
22+
23+
OBJS = ${SRCS:%.c=%.o}
24+
25+
OBJB = ${SRCB:%.c=%.o}
26+
27+
NAME = libft.a
28+
LIBC = ar rc
29+
CC = cc
30+
RM = rm -f
31+
CFLAGS = -Wall -Wextra -Werror
32+
33+
%.o : %.c libft.h
34+
${CC} ${CFLAGS} -c $<
35+
36+
all: ${NAME}
37+
38+
39+
${NAME}: ${OBJS}
40+
${LIBC} ${NAME} ${OBJS}
41+
42+
bonus: ${NAME} ${OBJB}
43+
${LIBC} ${NAME} ${OBJB}
44+
45+
clean:
46+
${RM} ${OBJS} ${OBJB}
47+
48+
fclean: clean
49+
${RM} ${NAME} ${bonus}
50+
51+
re: fclean all
52+
53+
.PHONY: all bonus clean fclean re

libft/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# libft

libft/ft_atoi.c

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_atoi.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/02 19:42:09 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/27 19:15:42 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
static int isoverflow(long long int check, long long int res)
16+
{
17+
if (res / 10 == check)
18+
return (0);
19+
return (1);
20+
}
21+
22+
static int is_sspace(const char *str, int *pt)
23+
{
24+
int i;
25+
int retsi;
26+
27+
i = 0;
28+
retsi = 1;
29+
while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
30+
i++;
31+
if (str[i] == '+' || str[i] == '-')
32+
{
33+
if (str[i] == '-')
34+
retsi *= -1;
35+
i++;
36+
}
37+
*pt = i;
38+
return (retsi);
39+
}
40+
41+
int ft_atoi(const char *str)
42+
{
43+
long long int r;
44+
int s;
45+
long long int check;
46+
int i;
47+
48+
r = 0;
49+
s = is_sspace(str, &i);
50+
while (str[i] >= '0' && str[i] <= '9')
51+
{
52+
check = r;
53+
r = r * 10 + (str[i] - '0');
54+
if (isoverflow(check, r) == 1)
55+
{
56+
if (s == -1)
57+
return (0);
58+
return (-1);
59+
}
60+
i++;
61+
}
62+
return (r * s);
63+
}

libft/ft_bzero.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_bzero.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/04 12:35:23 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/24 00:01:51 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void ft_bzero(void *s, size_t n)
16+
{
17+
ft_memset(s, 0, n);
18+
}

libft/ft_calloc.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_calloc.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/05 20:55:46 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/26 12:18:14 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void *ft_calloc(size_t count, size_t size)
16+
{
17+
char *memory;
18+
size_t other;
19+
20+
other = count * size;
21+
if (size != 0 && other / size != count)
22+
return (NULL);
23+
memory = malloc(other);
24+
if (memory == NULL)
25+
return (0);
26+
ft_bzero(memory, other);
27+
return (memory);
28+
}

libft/ft_isalnum.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalnum.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/01 13:48:49 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/27 18:20:51 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_isalnum(int c)
16+
{
17+
if ((c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122))
18+
return (1);
19+
return (0);
20+
}

libft/ft_isalpha.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalpha.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/01 13:26:09 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/27 18:20:48 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_isalpha(int c)
16+
{
17+
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
18+
return (1);
19+
return (0);
20+
}

libft/ft_isascii.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isascii.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/01 14:07:51 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/29 18:06:29 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_isascii(int c)
16+
{
17+
if (c >= 0 && c <= 127)
18+
return (1);
19+
return (0);
20+
}

libft/ft_isdigit.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isdigit.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/01 13:41:10 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/27 18:20:35 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_isdigit(int c)
16+
{
17+
if (c >= 48 && c <= 57)
18+
return (1);
19+
return (0);
20+
}

libft/ft_isprint.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isprint.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/01 14:18:52 by mjuicha #+# #+# */
9+
/* Updated: 2023/11/27 18:20:31 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_isprint(int c)
16+
{
17+
if (c >= 32 && c <= 126)
18+
return (1);
19+
return (0);
20+
}

libft/ft_itoa.c

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_itoa.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/09 14:16:37 by mjuicha #+# #+# */
9+
/* Updated: 2023/12/06 20:43:58 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
static int count_size(long int n)
16+
{
17+
long int i;
18+
19+
i = 0;
20+
if (n <= 0)
21+
i++;
22+
while (n != 0)
23+
{
24+
n = n / 10;
25+
i++;
26+
}
27+
return (i);
28+
}
29+
30+
char *ft_itoa(int n)
31+
{
32+
char *str;
33+
int s;
34+
int i;
35+
long int num;
36+
37+
i = count_size(n);
38+
num = n;
39+
str = (char *)malloc(sizeof(char) * (i + 1));
40+
if (!str)
41+
return (NULL);
42+
if (n < 0)
43+
{
44+
str[0] = '-';
45+
num *= -1;
46+
}
47+
s = i - 1;
48+
if (num == 0)
49+
str[s] = '0';
50+
while (s >= 0 && num != 0)
51+
{
52+
str[s--] = (num % 10) + '0';
53+
num = num / 10;
54+
}
55+
str[i] = '\0';
56+
return (str);
57+
}

libft/ft_lstadd_back_bonus.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_lstadd_back_bonus.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/12/08 10:09:04 by mjuicha #+# #+# */
9+
/* Updated: 2023/12/08 11:06:10 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void ft_lstadd_back(t_list **lst, t_list *new)
16+
{
17+
if (!lst || !new)
18+
return ;
19+
if (*lst)
20+
ft_lstlast(*lst)->next = new;
21+
else
22+
*lst = new;
23+
}

libft/ft_lstadd_front_bonus.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_lstadd_front_bonus.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mjuicha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/11/19 10:48:52 by mjuicha #+# #+# */
9+
/* Updated: 2023/12/08 10:00:48 by mjuicha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void ft_lstadd_front(t_list **lst, t_list *new)
16+
{
17+
if (!lst || !new)
18+
return ;
19+
new->next = *lst;
20+
*lst = new;
21+
}

0 commit comments

Comments
 (0)