This commit is contained in:
HexPloR
2024-06-24 00:02:52 +02:00
commit 4dfc0cd7ec
602 changed files with 5341 additions and 0 deletions
Executable
+31
View File
@@ -0,0 +1,31 @@
SOURCES = ft_putnbr_fd.c ft_putendl_fd.c ft_putstr_fd.c ft_putchar_fd.c ft_striteri.c ft_strmapi.c ft_itoa.c ft_split.c ft_strtrim.c ft_strjoin.c ft_substr.c ft_strdup.c ft_calloc.c ft_atoi.c ft_strnstr.c ft_memcmp.c ft_memchr.c ft_strncmp.c ft_strrchr.c ft_strchr.c ft_tolower.c ft_toupper.c ft_strlcpy.c ft_strlen.c ft_isprint.c ft_strlcat.c ft_memmove.c ft_memcpy.c ft_bzero.c ft_isalpha.c ft_isdigit.c ft_memset.c ft_isalnum.c ft_isascii.c
OBJECTS = $(SOURCES:.c=.o)
EXTRA = a.out a.out.dSYM main.c
NAME = libft.a
COMPILER = cc
FLAGS = -c -Wall -Werror -Wextra -I -g3
all : $(NAME)
$(NAME) : $(OBJECTS)
@ar -rcs libft.a *.o
$(OBJECTS) : $(SOURCES)
$(COMPILER) $(FLAGS) $(SOURCES)
clean :
@rm -f $(OBJECTS)
fclean : clean
@rm -rf $(NAME) $(EXTRA)
re :
@make fclean
@make all
.PHONY: fclean clean all re
+106
View File
@@ -0,0 +1,106 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/13 15:57:24 by hexplor #+# #+# */
/* Updated: 2023/11/27 22:23:38 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_isspace(char c)
{
if (c == '\t' || c == '\n' || c == '\v' \
|| c == '\f' || c == '\r' || c == ' ')
return (1);
return (0);
}
static int ft_fsign(char c)
{
if (c == '-')
return (-1);
return (1);
}
int ft_atoi(const char *text)
{
long sign;
long number;
number = 0;
sign = 1;
while (ft_isspace(*text) == 1)
text++;
if (*text == '-' || *text == '+')
{
sign = ft_fsign(*text);
text++;
}
while (ft_isdigit(*text) == 1)
{
number *= 10;
number += *text - '0';
text++;
}
return (sign * number);
}
/*
#include <stdlib.h>
#include <limits.h>
int main(void)
{
char *texte1 = "12";
char *texte2 = "+12";
char *texte3 = "-12";
char *texte4 = " \t\n\v\f\r12";
char *texte5 = " \t\n\v\f\r+12";
char *texte6 = " \t\n\v\f\r-12";
char *texte7 = "--12";
char *texte8 = "++12";
char *texte9 = "abcd7";
char *texte10 = "12abs";
char *texte11 = "";
char *texte12 = "0";
char *texte13 = "-2147483649";
char *texte14 = "2147483649";
if (ft_atoi(texte1) != 12)
printf("1: NON\n");
if(ft_atoi(texte2) != 12)
printf("2: NON\n");
if(ft_atoi(texte3) != -12)
printf("3: NON\n");
if(ft_atoi(texte4) != 12)
printf("4: NON\n");
if(ft_atoi(texte5) != 12)
printf("5: NON\n");
if(ft_atoi(texte6) != -12)
printf("6: NON\n");
if(ft_atoi(texte7) != 0)
printf("7: NON\n");
if(ft_atoi(texte8) != 0)
printf("8: NON\n");
if(ft_atoi(texte9) != 0)
printf("9: NON\n");
if(ft_atoi(texte10) != 12)
printf("10: NON\n");
if(ft_atoi(texte11) != 0)
printf("11: NON\n");
if(ft_atoi(texte12) != 0)
printf("12: NON\n");
if(ft_atoi(texte13) != -2147483649L)
printf("13: NON\n");
if(ft_atoi(texte14) != 2147483649L)
printf("14: NON\n");
write(1, "\n", 1);
return (0);
}*/
BIN
View File
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 10:47:55 by yantoine #+# #+# */
/* Updated: 2023/11/09 15:02:31 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
#include <stdio.h>
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
if (n <= 0)
return ;
ft_memset(s, 0, n);
}
/*int main()
{
void mess[10] = "oui";
ft_bzero()
return (0);
}*/
BIN
View File
Binary file not shown.
+42
View File
@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/14 15:24:33 by hexplor #+# #+# */
/* Updated: 2023/11/30 08:53:17 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t n, size_t size)
{
char *tab;
size_t sizemax;
sizemax = n * size;
if (size && sizemax / size < n)
return (NULL);
if (n == 0 || size == 0)
{
tab = malloc(1);
return (tab);
}
tab = malloc(n * size);
if (!tab)
return (NULL);
ft_bzero(tab, n * size);
return (tab);
}
/*#include <limits.h>
int main()
{
void *p;
p = ft_calloc(SIZE_MAX, SIZE_MAX);
free(p);
return (0);
}*/
BIN
View File
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 10:17:01 by yantoine #+# #+# */
/* Updated: 2023/11/08 08:05:51 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
if (ft_isalpha(c) == 1 || ft_isdigit(c) == 1)
return (1);
else
return (0);
}
BIN
View File
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 10:02:38 by yantoine #+# #+# */
/* Updated: 2023/11/08 08:06:13 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
if ((c >= 65 && c <= 90) \
|| (c >= 97 && c <= 122))
return (1);
else
return (0);
}
BIN
View File
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 10:17:41 by yantoine #+# #+# */
/* Updated: 2023/11/08 08:06:30 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
else
return (0);
}
BIN
View File
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 10:06:07 by yantoine #+# #+# */
/* Updated: 2023/11/08 08:06:49 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isdigit(int c)
{
if ((c >= 48 && c <= 57))
return (1);
else
return (0);
}
BIN
View File
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 12:37:20 by yantoine #+# #+# */
/* Updated: 2023/11/30 09:02:47 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
return (0);
}
BIN
View File
Binary file not shown.
+104
View File
@@ -0,0 +1,104 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/22 15:16:11 by hexplor #+# #+# */
/* Updated: 2023/11/30 07:44:52 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_n_digit(int n)
{
long index;
if (n == 0)
return (1);
index = 0;
while (n != 0)
{
n /= 10;
index++;
}
return (index);
}
static int ft_pow(int n)
{
long index;
index = 1;
while (n != 0)
{
index *= 10;
n--;
}
return (index / 10);
}
static void ft_set_number(char *tab)
{
long index;
index = 0;
while (index != 11)
{
tab[index] = index + '0';
index++;
}
tab[index] = '\0';
}
static void ft_set_digit(long nbr_digit, long index, char *nbr, long n)
{
char digit[15];
long pow;
if (n == 0)
{
*nbr = '0';
*(nbr + 1) = 0;
return ;
}
ft_set_number(digit);
pow = ft_pow(nbr_digit);
while (nbr_digit != 0)
{
*(nbr + index++) = digit[(n / pow) % 10];
nbr_digit--;
pow /= 10;
}
*(nbr + index++) = '\0';
}
char *ft_itoa(int n)
{
char *nbr;
long index;
long n2;
long nbr_digit;
n2 = (long) n;
nbr_digit = ft_n_digit(n);
index = 0;
if (n2 < 0)
{
nbr = ft_calloc((nbr_digit + 2), 1);
if (!nbr)
return (NULL);
*(nbr + index++) = '-';
n2 *= -1;
}
else
{
nbr = ft_calloc((nbr_digit + 1), 1);
if (!nbr)
return (NULL);
}
ft_set_digit(nbr_digit, index, nbr, n2);
return (nbr);
}
BIN
View File
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 09:03:40 by yantoine #+# #+# */
/* Updated: 2023/11/13 16:24:52 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *p;
size_t index;
p = (unsigned char *)s;
index = 0;
while (p[index] && index < n)
{
if (*(p + index) == (unsigned char) c)
return ((void *)(p + index));
index++;
}
return (NULL);
}
BIN
View File
Binary file not shown.
+37
View File
@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 10:08:42 by yantoine #+# #+# */
/* Updated: 2023/11/13 16:23:41 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *p1;
unsigned char *p2;
size_t index;
index = 0;
p1 = (unsigned char *)s1;
p2 = (unsigned char *)s2;
while (index < n)
{
if (*(p1 + index) != *(p2 + index))
return ((*(p1 + index) - *(p2 + index)));
index++;
}
return (0);
}
/*int main()
{
ft_memcmp("001270", "coucou", 7);
return (0);
}*/
BIN
View File
Binary file not shown.
+26
View File
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 11:03:13 by yantoine #+# #+# */
/* Updated: 2023/11/09 12:15:15 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
{
size_t index;
index = 0;
while (index < n)
{
*(unsigned char *)(dest + index) = *(unsigned char *)(src + index);
index++;
}
return (dest);
}
BIN
View File
Binary file not shown.
+40
View File
@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 15:13:56 by hexplor #+# #+# */
/* Updated: 2023/11/09 12:45:23 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t index;
int index2;
if (dest > src)
{
index2 = n - 1;
while (index2 >= 0)
{
*(unsigned char *)(dest + index2) = \
*(unsigned char *)(src + index2);
index2--;
}
}
else
{
index = 0;
while (index < n)
{
*(unsigned char *)(dest + index) = *(unsigned char *)(src + index);
index++;
}
}
return (dest);
}
BIN
View File
Binary file not shown.
+27
View File
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:33:18 by yantoine #+# #+# */
/* Updated: 2023/11/09 14:55:20 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
#include <stdio.h>
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
size_t index;
index = 0;
while (index < n)
{
*(unsigned char *)(s + index) = c;
index++;
}
return (s);
}
BIN
View File
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 14:08:31 by hexplor #+# #+# */
/* Updated: 2023/11/23 15:04:00 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}
BIN
View File
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 14:34:12 by hexplor #+# #+# */
/* Updated: 2023/11/24 17:45:40 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}
BIN
View File
Binary file not shown.
+87
View File
@@ -0,0 +1,87 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 14:41:48 by hexplor #+# #+# */
/* Updated: 2023/11/27 22:27:06 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_n_digit(int n)
{
long index;
index = 0;
while (n != 0)
{
n /= 10;
index++;
}
return (index);
}
static int ft_pow(int n)
{
long index;
index = 1;
while (n != 0)
{
index *= 10;
n--;
}
return (index / 10);
}
static void ft_set_number(char *tab)
{
long index;
index = 0;
while (index != 11)
{
tab[index] = index + '0';
index++;
}
tab[index] = '\0';
}
static void ft_set_digit(long nbr_digit, long n, int fd)
{
char digit[15];
long pow;
if (n == 0)
{
ft_putchar_fd('0', fd);
return ;
}
ft_set_number(digit);
pow = ft_pow(nbr_digit);
while (nbr_digit != 0)
{
ft_putchar_fd(digit[(n / pow) % 10], fd);
nbr_digit--;
pow /= 10;
}
}
void ft_putnbr_fd(int n, int fd)
{
long n2;
long nbr_digit;
n2 = (long) n;
nbr_digit = ft_n_digit(n);
if (n2 < 0)
{
ft_putchar_fd('-', fd);
n2 *= -1;
}
ft_set_digit(nbr_digit, n2, fd);
}
BIN
View File
Binary file not shown.
+25
View File
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 14:24:20 by hexplor #+# #+# */
/* Updated: 2023/11/23 14:32:00 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
unsigned int i;
i = 0;
while (*(s + i))
{
ft_putchar_fd(*(s + i), fd);
i++;
}
}
BIN
View File
Binary file not shown.
+108
View File
@@ -0,0 +1,108 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:06:15 by hexplor #+# #+# */
/* Updated: 2023/11/29 13:19:56 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t count_word(char *str, char c)
{
int count;
count = 0;
while (*str)
{
while (*str == c)
str++;
if (*str != c && *str)
count++;
while (*str && *str != c)
str++;
}
return (count);
}
static size_t len_word(char *s, char c, size_t start)
{
size_t i;
i = 0;
while (s[start] && s[start] != c)
{
i++;
start++;
}
return (i);
}
static void free_array(char **s1)
{
size_t i;
i = 0;
while (s1[i])
{
free(s1[i]);
i++;
}
free(s1);
}
static char **divisor(char *str1, char c, char **array, size_t len)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (i < len)
{
while (str1[j] && str1[j] == c)
j++;
array[i] = ft_substr(str1, j, len_word(str1, c, j));
if (!array[i])
{
free_array(array);
return (NULL);
}
while (str1[j] && str1[j] != c)
j++;
i++;
}
array[i] = NULL;
return (array);
}
char **ft_split(char const *s, char c)
{
size_t words;
char **array;
if (!s)
return (NULL);
words = count_word((char *)s, c);
array = (char **)malloc((words + 1) * (sizeof(char *)));
if (!array)
return (NULL);
array = divisor((char *)s, c, array, words);
return (array);
}
/*
int main()
{
char **list;
list = ft_split("--1-2--3---4----5-----42", '-');
for (int i = 0; list[i] != NULL; ++i)
free(list[i]);
free(list);
return (0);
}
*/
BIN
View File
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 12:07:02 by hexplor #+# #+# */
/* Updated: 2023/11/29 15:22:10 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
char *chaine;
chaine = (char *)s;
while (*chaine)
{
if (*chaine == (unsigned char)c)
return (chaine);
chaine++;
}
if (c == '\0')
return (chaine);
return (NULL);
}
BIN
View File
Binary file not shown.
+41
View File
@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/15 15:58:53 by hexplor #+# #+# */
/* Updated: 2023/11/29 14:52:09 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *s2;
int index;
s2 = (char *)ft_calloc(ft_strlen(s1) + 1, 1);
if (s2 == NULL)
return (NULL);
index = 0;
while (*(s1 + index))
{
*(s2 + index) = *(s1 + index);
index++;
}
*(s2 + index) = '\0';
return (s2);
}
/*int main()
{
char *dest;
dest = ft_strdup("BONJOUR");
dest = ft_strdup("");
dest = ft_strdup("\0");
return (0);
}*/
BIN
View File
Binary file not shown.
+26
View File
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 12:50:39 by hexplor #+# #+# */
/* Updated: 2023/11/23 13:54:15 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
unsigned int i;
i = 0;
while (*s)
{
f(i, s);
i++;
s++;
}
}
BIN
View File
Binary file not shown.
+28
View File
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 12:21:11 by hexplor #+# #+# */
/* Updated: 2023/11/30 08:49:26 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len;
char *str;
len = ft_strlen(s1);
len += ft_strlen(s2);
str = (char *)ft_calloc((len + 1), 1);
if (!str)
return (NULL);
ft_memmove(str, s1, ft_strlen(s1));
ft_memmove((str + ft_strlen(s1)), s2, ft_strlen(s2));
return (str);
}
BIN
View File
Binary file not shown.
+40
View File
@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 09:02:08 by hexplor #+# #+# */
/* Updated: 2023/11/10 09:54:44 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
size_t i;
size_t k;
i = 0;
k = 0;
while (dest[i] && i < size)
i++;
while (src[k] && (i + k + 1) < size)
{
dest[i + k] = src[k];
k++;
}
if (i < size)
dest[i + k] = '\0';
return (i + ft_strlen(src));
}
/*int main()
{
char mess1[10] = "oui";
char mess2[10] = "non";
ft_strlcat(mess1, mess2, 3);
return (0);
}*/
BIN
View File
Binary file not shown.
+43
View File
@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 17:27:30 by hexplor #+# #+# */
/* Updated: 2023/11/09 20:22:10 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dest, const char *src, size_t size)
{
size_t c;
size_t i;
c = 0;
while (src[c] != '\0')
c++;
i = 0;
if (size != 0)
{
while (src[i] != '\0' && i < (size - 1))
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
}
return (c);
}
/*int main()
{
char dest[10] = "oui";
char src[3] = "non";
ft_strlcpy(dest, src, 10);
return (0);
}*/
BIN
View File
Binary file not shown.
+22
View File
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 10:18:42 by yantoine #+# #+# */
/* Updated: 2023/11/09 12:31:17 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *c)
{
int index;
index = 0;
while (c[index] != 0)
index += 1;
return (index);
}
BIN
View File
Binary file not shown.
+31
View File
@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 11:52:03 by hexplor #+# #+# */
/* Updated: 2023/11/30 09:04:01 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *str;
i = 0;
str = ft_calloc((ft_strlen(s) + 1), 1);
if (!str)
return (0);
while (*(s + i))
{
*(str + i) = f(i, *(s + i));
i++;
}
*(str + i) = '\0';
return (str);
}
BIN
View File
Binary file not shown.
+28
View File
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 08:46:16 by yantoine #+# #+# */
/* Updated: 2023/11/30 09:28:36 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t index;
index = 0;
while (*(unsigned char *)(s1 + index) && \
*(unsigned char *)(s2 + index) && index < n)
{
if (*(s1 + index) != *(s2 + index))
return (*(s1 + index) - *(s2 + index));
index++;
}
return (0);
}
BIN
View File
Binary file not shown.
+46
View File
@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/12 12:16:17 by yantoine #+# #+# */
/* Updated: 2023/11/27 22:29:37 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
char *b;
b = (char *) big;
i = 0;
if (little[i] == '\0' || little == NULL)
return (b);
if (len == 0)
return (0);
while (b[i] != '\0' && i < len)
{
j = 0;
while (little[j] && (i + j) < len)
{
if (b[i + j] == little[j])
j++;
else
break ;
}
if (little[j] == 0)
return (&b[i]);
i++;
}
return (0);
}
/*int main()
{
ft_strnstr("aaabcabcd", "abcd", -1);
return (0);
}*/
BIN
View File
Binary file not shown.
+34
View File
@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 08:02:01 by yantoine #+# #+# */
/* Updated: 2023/11/29 14:34:30 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int len;
len = 0;
while (*s)
{
len++;
s++;
}
if (c == '\0' && *s == '\0')
return ((char *)s);
while (len >= 0)
{
if (*s == (unsigned char)c)
return ((char *)s);
s--;
len--;
}
return (NULL);
}
BIN
View File
Binary file not shown.
+27
View File
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 13:48:16 by hexplor #+# #+# */
/* Updated: 2023/11/29 13:09:29 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
int i;
int j;
i = 0;
j = ft_strlen(s1) - 1;
while (s1[i] && ft_strchr(set, s1[i]))
i++;
while (s1[j] && ft_strchr(set, s1[j]))
j--;
return (ft_substr(s1, i, (j - i + 1)));
}
BIN
View File
Binary file not shown.
+47
View File
@@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/15 20:04:44 by hexplor #+# #+# */
/* Updated: 2023/11/30 08:45:42 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
size_t i;
if (!s)
return (NULL);
i = 0;
if (len > ft_strlen(s) - start)
{
len = ft_strlen(s) - start;
}
if (start >= ft_strlen(s))
return (ft_strdup(""));
str = (char *)malloc(((sizeof(char) * (len + 1))));
if (!str)
return (NULL);
while (i < len && s[start] != '\0')
{
str[i++] = s[start++];
}
str[i] = '\0';
return (str);
}
/*
int main()
{
char *text;
text = ft_substr("tripouille", 100, 1);
free(text);
return (0);
}*/
BIN
View File
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 10:09:46 by hexplor #+# #+# */
/* Updated: 2023/11/10 10:13:40 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_tolower(int c)
{
if (c >= 97 - 32 && c <= 122 - 32)
return (c + 32);
return (c);
}
BIN
View File
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hexplor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 10:05:42 by hexplor #+# #+# */
/* Updated: 2023/11/10 10:09:20 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_toupper(int c)
{
if (c >= 97 && c <= 122)
return (c - 32);
return (c);
}
BIN
View File
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
Executable
+89
View File
@@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yantoine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 09:46:33 by yantoine #+# #+# */
/* Updated: 2023/11/23 14:41:28 by hexplor ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <limits.h>
void *ft_calloc(size_t count, size_t size);
void ft_putnbr_fd(int n, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_striteri(char *s, void (*f)(unsigned int, char*));
void *ft_memchr(const void *s, int c, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *s, int fd);
void *ft_memset(void *s, int c, size_t n);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
size_t ft_strlcat(char *dest, const char *src, size_t size);
size_t ft_strlcpy(char *dest, const char *src, size_t size);
size_t ft_strlen(const char *c);
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_strtrim(char const *s1, char const *set);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strdup(const char *s1);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
char *ft_strnstr(const char *big, const char *little, size_t len);
int ft_atoi(const char *str);
int ft_memcmp(const void *s1, const void *s2, size_t n);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_toupper(int c);
int ft_tolower(int c);
int ft_isprint(int c);
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalnum(int c);
int ft_isascii(int c);
#endif