Skip to content

Commit fd6a40e

Browse files
authored
Add files via upload
0 parents  commit fd6a40e

Some content is hidden

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

45 files changed

+1714
-0
lines changed

Makefile

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: ibeliaie <[email protected]> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2023/05/19 15:16:37 by ibeliaie #+# #+# #
9+
# Updated: 2023/05/22 17:28:49 by ibeliaie ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
NAME = libft.a
14+
15+
16+
SRC = ft_atoi.c \
17+
ft_itoa.c \
18+
ft_split.c \
19+
ft_bzero.c \
20+
ft_calloc.c \
21+
ft_memset.c \
22+
ft_memchr.c \
23+
ft_memcpy.c \
24+
ft_memcmp.c \
25+
ft_strdup.c \
26+
ft_strchr.c \
27+
ft_strlen.c \
28+
ft_substr.c \
29+
ft_isalpha.c \
30+
ft_isdigit.c \
31+
ft_isalnum.c \
32+
ft_isascii.c \
33+
ft_isprint.c \
34+
ft_tolower.c \
35+
ft_toupper.c \
36+
ft_memmove.c \
37+
ft_strrchr.c \
38+
ft_strnstr.c \
39+
ft_strncmp.c \
40+
ft_strlcat.c \
41+
ft_strlcpy.c \
42+
ft_strjoin.c \
43+
ft_strtrim.c \
44+
ft_strmapi.c \
45+
ft_striteri.c \
46+
ft_putnbr_fd.c \
47+
ft_putstr_fd.c \
48+
ft_putchar_fd.c \
49+
ft_putendl_fd.c
50+
51+
OBJ = $(SRC:.c=.o)
52+
53+
BONUS = ft_lstmap.c \
54+
ft_lstnew.c \
55+
ft_lstiter.c \
56+
ft_lstsize.c \
57+
ft_lstlast.c \
58+
ft_lstclear.c \
59+
ft_lstdelone.c \
60+
ft_lstadd_back.c \
61+
ft_lstadd_front.c
62+
63+
BONUS_OBJ =$(BONUS:.c=.o)
64+
65+
CC = gcc
66+
FLAGS = -Wall -Wextra -Werror
67+
68+
RM = rm -rf
69+
70+
71+
all: $(NAME)
72+
73+
$(NAME): $(OBJ)
74+
ar -rsc $(NAME) $(OBJ)
75+
76+
bonus: $(OBJ) $(BONUS_OBJ)
77+
ar -rsc $(NAME) $(OBJ) $(BONUS_OBJ)
78+
79+
clean:
80+
$(RM) $(OBJ) $(BONUS_OBJ)
81+
82+
fclean: clean
83+
$(RM) $(NAME)
84+
85+
re: fclean all
86+
87+
.PHONY: all clean fclean re bonus

ft_atoi.c

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_atoi.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/05/17 12:03:01 by ibeliaie #+# #+# */
9+
/* Updated: 2023/05/23 12:40:16 by ibeliaie ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* convert str representation of int to int value */
16+
int ft_atoi(const char *str)
17+
{
18+
int i;
19+
int sign;
20+
int result;
21+
22+
sign = 1;
23+
i = 0;
24+
result = 0;
25+
while (*str == 32 || (*str >= 9 && *str <= 13))
26+
str++;
27+
if (*str == '-')
28+
sign *= -1;
29+
while (*str == '-' || *str == '+')
30+
{
31+
str++;
32+
i++;
33+
}
34+
while (*str >= '0' && *str <= '9')
35+
{
36+
result = result * 10 + *str - '0';
37+
str++;
38+
}
39+
if (i > 1)
40+
return (0);
41+
return (result * sign);
42+
}
43+
44+
// int main()
45+
// {
46+
// const char *str = "-42";
47+
// int result = ft_atoi(str);
48+
// printf("Result: %d\n", result);
49+
// return (0);
50+
// }
51+
52+
// if current result is 23 and current digit is '5' :
53+
// 1. result * 10 : 23 * 10 = 230 (make room for next digit)
54+
// 2. + *str : 230 + '5' = 230 + 5 = 235 (add current digit character to result)
55+
// 3. - '0' : 235 - 48 = 235 (subtract ascii value of '0' to convert character
56+
// to digit of it's corresponding numeric value)

ft_bzero.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_bzero.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/05/16 14:44:01 by ibeliaie #+# #+# */
9+
/* Updated: 2023/05/23 12:47:35 by ibeliaie ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* set a block of memory to zero */
16+
void ft_bzero(void *s, size_t len)
17+
{
18+
size_t i;
19+
unsigned char *ptr;
20+
21+
i = 0;
22+
ptr = (unsigned char *)s;
23+
while (i < len)
24+
{
25+
ptr[i] = 0;
26+
i++;
27+
}
28+
}
29+
30+
// int main()
31+
// {
32+
// char str[10] = "bonjour";
33+
// printf("Before: %s\n", str);
34+
// ft_bzero(str, strlen(str));
35+
// printf("After: %s\n", str);
36+
// return (0);
37+
// }

ft_calloc.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_calloc.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/05/17 12:41:58 by ibeliaie #+# #+# */
9+
/* Updated: 2023/05/20 11:40:55 by ibeliaie ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* allocate and zero-initialize block of memory */
16+
void *ft_calloc(size_t count, size_t size)
17+
{
18+
void *ptr;
19+
size_t total_size;
20+
21+
total_size = count * size;
22+
ptr = malloc(total_size);
23+
if (!ptr)
24+
return (NULL);
25+
return (ft_memset (ptr, 0, total_size));
26+
}

ft_isalnum.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalnum.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/05/15 17:49:25 by ibeliaie #+# #+# */
9+
/* Updated: 2023/05/20 18:39:36 by ibeliaie ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* check if character is alphanumeric */
16+
int ft_isalnum(int c)
17+
{
18+
if (ft_isdigit(c) || ft_isalpha(c))
19+
return (c);
20+
return (0);
21+
}

ft_isalpha.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalpha.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/05/15 17:42:51 by ibeliaie #+# #+# */
9+
/* Updated: 2023/05/18 17:21:29 by ibeliaie ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* check if character is alphabetic */
16+
int ft_isalpha(int c)
17+
{
18+
return ((c >= 65 && c <= 90) || (c >= 97 && c <= 122));
19+
}

ft_isascii.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isascii.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/05/15 18:02:16 by ibeliaie #+# #+# */
9+
/* Updated: 2023/05/18 17:21:32 by ibeliaie ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* check if character is ascii */
16+
int ft_isascii(int c)
17+
{
18+
return (c >= 0 && c < 128);
19+
}

ft_isdigit.c

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

ft_isprint.c

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

ft_itoa.c

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_itoa.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/05/19 13:25:28 by ibeliaie #+# #+# */
9+
/* Updated: 2023/05/23 13:09:39 by ibeliaie ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* number of digits in int */
16+
static int count(int n)
17+
{
18+
int i;
19+
20+
i = 0;
21+
if (n <= 0)
22+
i++;
23+
while (n != 0)
24+
{
25+
n /= 10;
26+
i++;
27+
}
28+
return (i);
29+
}
30+
31+
/* convert int to str */
32+
static char *convert(int len, int p, char *ptr, int n)
33+
{
34+
while (len + 1 > p)
35+
{
36+
if (n < 0)
37+
ptr[len] = n % 10 * (-1) + '0';
38+
else
39+
ptr[len] = n % 10 + '0';
40+
n /= 10;
41+
len--;
42+
}
43+
return (ptr);
44+
}
45+
46+
/* convert integer to string */
47+
char *ft_itoa(int n)
48+
{
49+
char *ptr;
50+
int len;
51+
int position;
52+
53+
len = 0;
54+
len = count(n);
55+
ptr = (char *) malloc (len + 1);
56+
if (!ptr)
57+
return (NULL);
58+
position = 0;
59+
if (n < 0)
60+
{
61+
ptr[0] = '-';
62+
position = 1;
63+
}
64+
ptr[len] = '\0';
65+
len--;
66+
return (convert(len, position, ptr, n));
67+
}

0 commit comments

Comments
 (0)