Skip to content

Commit 7aebffd

Browse files
committed
done
1 parent e0c0f8f commit 7aebffd

Some content is hidden

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

63 files changed

+2467
-0
lines changed

Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: ariahi <ariahi@student.42.fr> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2021/11/14 15:25:14 by ariahi #+# #+# #
9+
# Updated: 2023/01/17 14:14:06 by ariahi ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
Src = ft_strlen.c ft_strlcpy.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strnstr.c\
14+
ft_strncmp.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c\
15+
ft_toupper.c ft_tolower.c ft_atoi.c ft_memcmp.c ft_memset.c ft_memcpy.c\
16+
ft_memmove.c ft_memchr.c ft_bzero.c ft_calloc.c ft_strdup.c ft_substr.c\
17+
ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strcmp.c ft_striteri.c\
18+
ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_putchar_fd.c ft_strsep.c\
19+
ft_strcspn.c ft_strnlen.c ft_lstput_orderly.c lst_put_orderly_sorted.c\
20+
ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back.c\
21+
ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_atoll.c ft_lstremove.c ft_strspn.c lst_put_orderly_sorted_2.c ft_2d_len.c ft_free.c\
22+
gnl/get_next_line.c gnl/get_next_line_utils.c ft_printf/ft_printf.c ft_printf/ft_put_D.c ft_printf/ft_put_X.c
23+
24+
Cc = gcc
25+
Flags = -Wall -Wextra -Werror -g
26+
Name = libft.a
27+
28+
Obj = $(Src:.c=.o)
29+
30+
$(Name): $(Obj)
31+
ar cr $(Name) $(Obj)
32+
33+
all: $(Name)
34+
35+
gnl/%.o: gnl/%.c
36+
$(Cc) $(Flags) -c -o $@ $<
37+
38+
ft_printf/%.o: ft_printf/%.c
39+
$(Cc) $(Flags) -c -o $@ $<
40+
41+
%.o: %.c libft.h
42+
$(Cc) $(Flags) -c -o $@ $<
43+
44+
bonus: $(Obj)
45+
ar cr $(Name) $(Obj)
46+
47+
clean:
48+
rm -rf $(Obj)
49+
50+
fclean: clean
51+
rm -rf $(Name) get_next_line_utils.o get_next_line.o
52+
53+
re: fclean all
54+
55+
.PHONY: all bonus clean fclean re

ft_2d_len.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_2d_len.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: eel-moun <eel-moun@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/12/31 16:44:59 by ariahi #+# #+# */
9+
/* Updated: 2023/01/14 13:22:16 by eel-moun ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_2d_len(char **av)
16+
{
17+
int len;
18+
19+
len = 0;
20+
if (!av)
21+
return (-1);
22+
while (av[len])
23+
len++;
24+
return (len);
25+
}

ft_atoi.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_atoi.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <marvin@42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/02 19:10:27 by ariahi #+# #+# */
9+
/* Updated: 2021/11/15 23:49:36 by ariahi ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_atoi(const char *str)
16+
{
17+
int sign;
18+
int res;
19+
int i;
20+
21+
sign = 1;
22+
res = 0;
23+
i = 0;
24+
while (str[i] == ' ' || str[i] == '\n' || str[i] == '\t' || str[i] == '\v'
25+
|| str[i] == '\f' || str[i] == '\r')
26+
i++;
27+
if (str[i] == '-' || str[i] == '+')
28+
{
29+
if (str[i] == '-')
30+
sign = -1;
31+
i++;
32+
}
33+
while (str[i] >= 48 && str[i] <= 57)
34+
{
35+
res = res * 10 + str[i] - 48;
36+
i++;
37+
}
38+
return (res * sign);
39+
}

ft_atoll.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_atoll.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <ariahi@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/09/06 19:14:01 by ariahi #+# #+# */
9+
/* Updated: 2022/12/28 08:55:09 by ariahi ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
#include <limits.h>
15+
#include <errno.h>
16+
17+
long long ft_atoll(const char *str)
18+
{
19+
long long res;
20+
int sign;
21+
int nb;
22+
int i;
23+
24+
i = 0;
25+
sign = 1;
26+
res = 0;
27+
while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
28+
i++;
29+
if (str[i] == '+' || str[i] == '-')
30+
if (str[i++] == '-')
31+
sign = -1;
32+
while (ft_isdigit(str[i]))
33+
{
34+
nb = (str[i++] - 48);
35+
if (sign == 1 && (LLONG_MAX - res) / 10 < res)
36+
return (errno = ERANGE, LLONG_MAX);
37+
if (sign == -1 && (LLONG_MIN + res) / 10 > res)
38+
return (errno = ERANGE, LLONG_MIN);
39+
res = res * 10 + nb * sign;
40+
}
41+
return (res);
42+
}

ft_bzero.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_bzero.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <marvin@42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/03 11:06:52 by ariahi #+# #+# */
9+
/* Updated: 2021/11/27 12:03:30 by ariahi ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void ft_bzero(void *s, size_t n)
16+
{
17+
size_t i;
18+
19+
i = -1;
20+
while (++i < n)
21+
((char *)s)[i] = 0;
22+
}

ft_calloc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_calloc.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <marvin@42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/11 23:03:03 by ariahi #+# #+# */
9+
/* Updated: 2021/11/27 17:10:33 by ariahi ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void *ft_calloc(size_t count, size_t size)
16+
{
17+
void *s;
18+
19+
s = (char *)malloc(count * size);
20+
if (!s)
21+
return (NULL);
22+
ft_bzero(s, count * size);
23+
return (s);
24+
}

ft_free.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_free.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <ariahi@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/12/31 16:49:04 by ariahi #+# #+# */
9+
/* Updated: 2022/12/31 16:49:13 by ariahi ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void ft_free(char **s)
16+
{
17+
int i;
18+
19+
i = 0;
20+
while (s[i])
21+
free(s[i++]);
22+
free(s);
23+
}

ft_isalnum.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalnum.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <marvin@42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/01 13:57:25 by ariahi #+# #+# */
9+
/* Updated: 2021/11/10 13:53:43 by ariahi ### ########.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+
}

ft_isalpha.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalpha.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <marvin@42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/01 10:03:44 by ariahi #+# #+# */
9+
/* Updated: 2021/11/10 13:48:11 by ariahi ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_isalpha(int alpha)
16+
{
17+
if ((alpha >= 65 && alpha <= 90) || (alpha >= 97 && alpha <= 122))
18+
return (1);
19+
return (0);
20+
}

ft_isascii.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isascii.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <marvin@42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/01 14:24:37 by ariahi #+# #+# */
9+
/* Updated: 2021/11/10 13:58:30 by ariahi ### ########.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+
}

ft_isdigit.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isdigit.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <marvin@42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/01 13:33:04 by ariahi #+# #+# */
9+
/* Updated: 2021/11/10 13:49:33 by ariahi ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
int ft_isdigit(int digit)
16+
{
17+
if (digit >= 48 && digit <= 57)
18+
return (1);
19+
return (0);
20+
}

ft_isprint.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isprint.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ariahi <ariahi@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/11/01 15:54:15 by ariahi #+# #+# */
9+
/* Updated: 2022/12/28 08:54:06 by ariahi ### ########.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+
}

ft_itoa.c

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

0 commit comments

Comments
 (0)