add: extra function

This commit is contained in:
Camille Chauvet
2023-05-03 11:11:04 +00:00
parent 3ad6814405
commit 88d69ebcea
8 changed files with 108 additions and 71 deletions

View File

@ -6,13 +6,13 @@
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
# Updated: 2023/04/26 12:14:25 by cchauvet ### ########.fr #
# Updated: 2023/05/03 11:01:55 by cchauvet ### ########.fr #
# #
# **************************************************************************** #
CC = clang
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c ft_tablen.c
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c ft_tablen.c ft_atoul.c ft_atoul_check.c
OBJS = $(SRCS:.c=.o)

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
/* Updated: 2023/04/26 12:24:00 by cchauvet ### ########.fr */
/* Updated: 2023/05/03 11:02:33 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,28 +14,31 @@
# define EXTRA_H
# include <stdarg.h>
# include <stdlib.h>
#include <sys/types.h>
# include <unistd.h>
# include <fcntl.h>
# include "../libft/libft.h"
size_t ft_tablen(const char **tab);
char *ft_ultoa_base(unsigned long long n, char *base);
char *get_next_line(int fd);
size_t ft_random_generator(size_t start, size_t stop);
void ft_freer_tab_ultimate(size_t len, ...);
void ft_freer_ultimate(size_t len, ...);
char *ft_strgen(char c, size_t len);
char *ft_strfjoin(char *s1, char *s2);
char *ft_strmerger(size_t arg_len, ...);
int ft_is_in(char *str, char c);
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
char *ft_strndup(const char *src, size_t n);
ssize_t ft_strchri(char *str, char c);
int ft_contain_only_str(char *str, char *to_find);
int ft_contain_only(char *str, char c);
int ft_strcmp(const char *s1, const char *s2);
void ft_swap(void *a, void *b);
void ft_swap_int(int *a, int *b);
void ft_swap_char(char *a, char *b);
unsigned long ft_atoul(const char str[]);
int ft_atoul_check(const char str[]);
size_t ft_tablen(const void **tab);
char *ft_ultoa_base(unsigned long long n, char *base);
char *get_next_line(int fd);
size_t ft_random_generator(size_t start, size_t stop);
void ft_freer_tab_ultimate(size_t len, ...);
void ft_freer_ultimate(size_t len, ...);
char *ft_strgen(char c, size_t len);
char *ft_strfjoin(char *s1, char *s2);
char *ft_strmerger(size_t arg_len, ...);
int ft_is_in(const char *str, char c);
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
char *ft_strndup(const char *src, size_t n);
ssize_t ft_strchri(char *str, char c);
int ft_contain_only_str(const char *str, const char *to_find);
int ft_contain_only(const char *str, char c);
int ft_strcmp(const char *s1, const char *s2);
void ft_swap(void *a, void *b);
void ft_swap_int(int *a, int *b);
void ft_swap_char(char *a, char *b);
#endif

38
libftx/extra/ft_atoul.c Normal file
View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoul.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
/* Updated: 2023/05/03 11:03:04 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
unsigned long ft_atoul(const char *str)
{
unsigned long out;
char sign;
size_t i;
sign = 1;
i = 0;
while (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
sign = -1;
if (str[i] == '+')
sign = 1;
i++;
}
out = 0;
while (str[i] >= '0' && str[i] <= '9')
{
out = out * 10 + str[i] - 48;
i++;
}
return (out * sign);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoul_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 14:43:33 by cchauvet #+# #+# */
/* Updated: 2023/05/02 13:15:12 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./extra.h"
int ft_atoul_check(const char str[])
{
size_t i;
unsigned long num;
num = 0;
i = 0;
while (str[i] != '\0')
{
if (str[i] > '9' || str[i] < '0')
return (0);
if (num > num * 10 + str[i] - '0')
return (0);
num = num * 10 + str[i] - 48;
i++;
}
return (1);
}

View File

@ -6,13 +6,13 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/12 16:28:20 by cchauvet #+# #+# */
/* Updated: 2023/01/12 16:31:22 by cchauvet ### ########.fr */
/* Updated: 2023/04/26 13:07:06 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
int ft_contain_only(char *str, char c)
int ft_contain_only(const char *str, char c)
{
size_t i;
@ -26,7 +26,7 @@ int ft_contain_only(char *str, char c)
return (1);
}
int ft_contain_only_str(char *str, char *to_find)
int ft_contain_only_str(const char *str, const char *to_find)
{
size_t i;

View File

@ -6,13 +6,13 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/05 20:29:53 by cchauvet #+# #+# */
/* Updated: 2023/01/08 12:15:08 by cchauvet ### ########.fr */
/* Updated: 2023/04/26 13:07:30 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
int ft_is_in(char *str, char c)
int ft_is_in(const char *str, char c)
{
int i;

View File

@ -6,13 +6,13 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 12:12:19 by cchauvet #+# #+# */
/* Updated: 2023/04/26 12:13:38 by cchauvet ### ########.fr */
/* Updated: 2023/04/28 12:58:24 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./extra.h"
size_t ft_tablen(const char **tab)
size_t ft_tablen(const void **tab)
{
size_t i;