-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tat Hoang Nguyen
committed
Nov 13, 2024
1 parent
e42767a
commit 634f936
Showing
45 changed files
with
2,318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2024/11/07 15:19:42 by tat-nguy #+# #+# # | ||
# Updated: 2024/11/09 12:15:16 by tat-nguy ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
# Variables | ||
NAME = libft.a | ||
CC = cc | ||
CFLAGS = -Wall -Wextra -Werror | ||
AR = ar -rc | ||
RANLIB = ranlib | ||
RM = rm -rf | ||
|
||
# Paths and Files | ||
SRCS = ft_atoi.c ft_bzero.c ft_calloc.c ft_isalnum.c ft_isalpha.c \ | ||
ft_isascii.c ft_isdigit.c ft_isprint.c ft_memchr.c \ | ||
ft_memcmp.c ft_memcpy.c ft_memmove.c ft_memset.c ft_strchr.c \ | ||
ft_strdup.c ft_strlcat.c ft_strlcpy.c ft_strlen.c \ | ||
ft_strncmp.c ft_strnstr.c ft_strrchr.c ft_tolower.c \ | ||
ft_toupper.c ft_itoa.c ft_putchar_fd.c ft_putendl_fd.c \ | ||
ft_putnbr_fd.c ft_putstr_fd.c ft_split.c ft_striteri.c \ | ||
ft_strjoin.c ft_strmapi.c ft_strtrim.c ft_substr.c | ||
|
||
OBJS = $(SRCS:.c=.o) | ||
|
||
BONUS_SRCS = ft_lstadd_back_bonus.c ft_lstadd_front_bonus.c \ | ||
ft_lstclear_bonus.c ft_lstdelone_bonus.c ft_lstiter_bonus.c \ | ||
ft_lstlast_bonus.c ft_lstmap_bonus.c ft_lstnew_bonus.c \ | ||
ft_lstsize_bonus.c | ||
|
||
BONUS_OBJS = $(BONUS_SRCS:.c=.o) | ||
|
||
INCLUDE = . | ||
|
||
# Rules | ||
all: $(NAME) | ||
|
||
$(NAME): $(OBJS) | ||
$(AR) $(NAME) $(OBJS) | ||
$(RANLIB) $(NAME) | ||
|
||
bonus: $(BONUS_OBJS) | ||
$(AR) $(NAME) $(BONUS_OBJS) | ||
$(RANLIB) $(NAME) | ||
|
||
.c.o: | ||
$(CC) $(CFLAGS) -I $(INCLUDE) -c $< -o $@ | ||
|
||
clean: | ||
$(RM) $(OBJS) $(BONUS_OBJS) | ||
|
||
fclean: clean | ||
$(RM) $(NAME) | ||
|
||
re: fclean all | ||
|
||
.PHONY: all clean fclean re bonus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_atoi.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/05 16:04:40 by tat-nguy #+# #+# */ | ||
/* Updated: 2024/11/08 18:56:32 by tat-nguy ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
static int ft_isspace(int c) | ||
{ | ||
if (c == ' ' || c == '\f' || c == '\n' || c == '\r' | ||
|| c == '\t' || c == '\v') | ||
return (8192); | ||
else | ||
return (0); | ||
} | ||
|
||
int ft_atoi(const char *nptr) | ||
{ | ||
int i; | ||
int nb; | ||
int sign; | ||
|
||
i = 0; | ||
nb = 0; | ||
sign = 1; | ||
while (ft_isspace(nptr[i]) != 0) | ||
i++; | ||
if (nptr[i] == '-') | ||
{ | ||
sign = -1; | ||
i++; | ||
} | ||
else if (nptr[i] == '+') | ||
i++; | ||
while (nptr[i] >= '0' && nptr[i] <= '9') | ||
{ | ||
nb = nb * 10 + (nptr[i] - '0'); | ||
i++; | ||
} | ||
return (nb * sign); | ||
} | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
int main(void) | ||
{ | ||
char *str = " 2147483647"; | ||
printf("atoi: %i\n", atoi(str)); | ||
printf("ft_atoi: %i\n", ft_atoi(str)); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_bzero.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/05 18:26:29 by tat-nguy #+# #+# */ | ||
/* Updated: 2024/11/05 18:26:32 by tat-nguy ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
void ft_bzero(void *s, size_t n) | ||
{ | ||
size_t i; | ||
|
||
i = 0; | ||
while (i < n) | ||
{ | ||
((char *)s)[i] = '\0'; | ||
i++; | ||
} | ||
} | ||
|
||
/* | ||
#include <stdio.h> | ||
#include <strings.h> | ||
int main(void) | ||
{ | ||
unsigned int i = 0; | ||
unsigned int n = 4; | ||
char s1[20] = "This is 42 Perpignan"; | ||
bzero(s1, n); | ||
printf("bzero: "); | ||
while (i < 19) | ||
{ | ||
if (s1[i] == '\0') | ||
printf("."); | ||
else | ||
printf("%c", s1[i]); | ||
i++; | ||
} | ||
printf("\n"); | ||
i = 0; | ||
char s2[20] = "This is 42 Perpignan"; | ||
ft_bzero(s2, n); | ||
printf("ft_bzero: "); | ||
while (i < 19) | ||
{ | ||
if (s2[i] == '\0') | ||
printf("/"); | ||
else | ||
printf("%c", s2[i]); | ||
i++; | ||
} | ||
printf("\n"); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_calloc.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/05 19:20:54 by tat-nguy #+# #+# */ | ||
/* Updated: 2024/11/05 19:23:32 by tat-nguy ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
// it allocate memory like malloc but then it set memory to '0' each bytes | ||
// nmemb: number of elements, size: bytes each member | ||
|
||
#include "libft.h" | ||
|
||
void *ft_calloc(size_t nmemb, size_t size) | ||
{ | ||
void *s; | ||
size_t total_size; | ||
size_t i; | ||
|
||
total_size = nmemb * size; | ||
s = malloc(total_size); | ||
if (s == NULL) | ||
return (NULL); | ||
i = 0; | ||
while (i < total_size) | ||
{ | ||
((char *)s)[i] = 0; | ||
i++; | ||
} | ||
return (s); | ||
} | ||
|
||
/* | ||
#include <stdio.h> | ||
int main(void) | ||
{ | ||
int *array = ft_calloc(4, sizeof(int)); | ||
int i = 0; | ||
while (i < 4) | ||
{ | ||
printf("%i", array[i]); | ||
i++; | ||
} | ||
free(array); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_isalnum.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/04 17:53:49 by tat-nguy #+# #+# */ | ||
/* Updated: 2024/11/04 18:44:58 by tat-nguy ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_isalnum(int c) | ||
{ | ||
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') | ||
|| (c >= 'A' && c <= 'Z')) | ||
return (1); | ||
else | ||
return (0); | ||
} | ||
|
||
/* | ||
#include <ctype.h> | ||
#include <stdio.h> | ||
int main(void) | ||
{ | ||
int c = '?'; | ||
printf("isalnum: %i\n", isalnum(c)); | ||
printf("ft_isalnum: %i\n", ft_isalnum(c)); | ||
return (0); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_isalpha.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/04 13:43:38 by tat-nguy #+# #+# */ | ||
/* Updated: 2024/11/08 18:20:58 by tat-nguy ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_isalpha(int c) | ||
{ | ||
if ((c > 64 && c < 91) || (c > 96 && c < 123)) | ||
return (1024); | ||
else | ||
return (0); | ||
} | ||
|
||
/* | ||
#include <stdio.h> | ||
#include <ctype.h> | ||
int main(void) | ||
{ | ||
int c = 'a'; | ||
int i = isalpha(c); | ||
printf("isalpha: %i\n", i); | ||
int a = ft_isalpha(c); | ||
printf("ft_isalpha: %i\n", a); | ||
return (0); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_isascii.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tat-nguy <tat-nguy@student.42perpignan.fr +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/04 19:22:35 by tat-nguy #+# #+# */ | ||
/* Updated: 2024/11/04 20:21:34 by tat-nguy ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_isascii(int c) | ||
{ | ||
if (c >= 0 && c <= 127) | ||
return (1); | ||
else | ||
return (0); | ||
} | ||
|
||
/* | ||
#include <ctype.h> | ||
#include <stdio.h> | ||
int main(void) | ||
{ | ||
int c = 200; | ||
printf("isascii: %i\n", isascii(c)); | ||
printf("ft_isascii: %i\n", ft_isascii(c)); | ||
return (0); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_isdigit.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/04 14:55:31 by tat-nguy #+# #+# */ | ||
/* Updated: 2024/11/04 15:01:35 by tat-nguy ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_isdigit(int c) | ||
{ | ||
if (c >= '0' && c <= '9') | ||
return (2048); | ||
else | ||
return (0); | ||
} | ||
|
||
/* | ||
#include <ctype.h> | ||
#include <stdio.h> | ||
int main(void) | ||
{ | ||
int c = ':'; | ||
printf("isdigit: %i\n", isdigit(c)); | ||
printf("ft_isdigit: %i\n", ft_isdigit(c)); | ||
return (0); | ||
} | ||
*/ |
Oops, something went wrong.