commit 29ed24d567fa21245a1d2292589c2302820dddb5 Author: Camille Chauvet Date: Wed May 17 16:45:25 2023 +0000 init diff --git a/BSQ/Makefile b/BSQ/Makefile new file mode 100644 index 0000000..8f13bb6 --- /dev/null +++ b/BSQ/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lflandri +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/07/30 09:24:04 by nlocusso #+# #+# # +# Updated: 2022/08/03 14:43:35 by lflandri ### ########.fr # +# # +# **************************************************************************** # + +SRCS = ft_mapcmp.c ft_is_printable.c ft_contain_only.c ft_write_map.c file_reader.c ft_putstr.c find_square.c standart_entry_reader.c ft_strstr.c ft_tablen.c ft_strndup.c main.c ft_atou.c ft_strlen.c ft_is_digit.c ft_duplicated.c ft_split.c map_reader.c ft_strcat.c + + +PO = ${SRCS:.c=.o} + +NAME = bsq + +all : ${NAME} + +${NAME}: ${PO} + gcc -o ${NAME} -Wall -Wextra -Werror ${PO} + +.c.o : $(PO) + gcc -c -Wall -Wextra -Werror $< -o ${<:.c=.o} + +clean : + rm -f ${PO} + +fclean : clean + rm -f ${NAME} + +re : fclean all + +.PHONY : all clean fclean re diff --git a/BSQ/bsq b/BSQ/bsq new file mode 100755 index 0000000..8be683b Binary files /dev/null and b/BSQ/bsq differ diff --git a/BSQ/bsq.h b/BSQ/bsq.h new file mode 100644 index 0000000..c449bb7 --- /dev/null +++ b/BSQ/bsq.h @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* bsq.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/01 20:56:40 by cchauvet #+# #+# */ +/* Updated: 2022/08/03 12:44:34 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef BSQ_H +# define BSQ_H +# include +# include +# include +# include +# include + +struct s_map { + char obstacle; + char clear; + char full; + unsigned int v_len; + unsigned int h_len; +}; +typedef struct s_map t_map_property; +struct s_square +{ + int x; + int y; + int size; +}; +typedef struct s_square t_square; +int ft_duplicated(char *str); +int ft_is_printable(char *str); +void starting_crea_map(char *path, char *str_entry); +void read_standart_entry(void); +void free_map(char **map); +unsigned int ft_atou(char *str); +unsigned int ft_mapcmp(t_map_property p1, t_map_property p2); +int ft_is_digit(char *str); +unsigned int ft_contain_only(char **str, char *charset); +unsigned int ft_tablen(char **tab); +char **ft_atomap(char *str, t_map_property *property); +char *ft_strcat(char *dest, char *src); +void write_map(char **map, t_map_property map_p); +char **ft_split(char *str, char *sep); +char *ft_strndup(char *src, unsigned int n); +unsigned int ft_strlen(char *str); +int ft_strstr(char *str, char *to_find); +char *ft_filereader(char *path); +void replace_map(char **map, t_square squarre, t_map_property map_p); +t_square point_checker(char **map, t_map_property map_p); +#endif diff --git a/BSQ/file_reader.c b/BSQ/file_reader.c new file mode 100644 index 0000000..3fe62ea --- /dev/null +++ b/BSQ/file_reader.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* file_reader.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/01 20:55:35 by cchauvet #+# #+# */ +/* Updated: 2022/08/02 14:22:34 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +int ft_filelen(char *path) +{ + int file_descriptor; + int letter_readed_counter; + char letters_readed[10]; + int length; + + file_descriptor = open(path, O_RDONLY); + if (file_descriptor == -1) + return (-1); + length = 0; + letter_readed_counter = -1; + while (letter_readed_counter != 0) + { + letter_readed_counter = read(file_descriptor, letters_readed, 10); + length = length + letter_readed_counter; + } + if (close(file_descriptor) == -1) + return (-1); + return (length); +} + +char *ft_filereader(char *path) +{ + char *str; + int file_descriptor; + int length; + + length = ft_filelen(path); + if (length < 1) + { + str = malloc(sizeof(*str)); + str[0] = 0; + return (str); + } + str = malloc(sizeof(*str) * (length + 1)); + file_descriptor = open(path, O_RDONLY); + if (file_descriptor == -1) + { + str[0] = 0; + return (str); + } + read(file_descriptor, str, length); + str[length - 1] = 0; + if (close(file_descriptor) == -1) + str[0] = 0; + return (str); +} diff --git a/BSQ/file_reader.o b/BSQ/file_reader.o new file mode 100644 index 0000000..130f43a Binary files /dev/null and b/BSQ/file_reader.o differ diff --git a/BSQ/find_square.c b/BSQ/find_square.c new file mode 100644 index 0000000..e4498d1 --- /dev/null +++ b/BSQ/find_square.c @@ -0,0 +1,159 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_square.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/01 21:09:15 by lflandri #+# #+# */ +/* Updated: 2022/08/02 18:37:53 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +void init_t_squarre(t_square *square, int x, int y, int size) +{ + (*square).size = size; + (*square).x = x; + (*square).y = y; +} + +t_square find_the_biggest_square(t_square square1, t_square square2) +{ + if (square1.size >= square2.size) + return (square1); + return (square2); +} + +int right_bottom_square_checker(t_square square, + unsigned int ind, char **map, t_map_property map_p) +{ + unsigned int ind2; + + ind2 = 0; + while (ind2 != ind + 1) + { + if (map[square.y + ind][square.x + ind2] != map_p.obstacle + && map[square.y + ind2][square.x + ind] != map_p.obstacle) + ind2++; + else + return (0); + } + return (1); +} + +t_square left_top_square_checker(t_square square, char **map, + t_map_property map_p) +{ + unsigned int ind; + + ind = 0; + while (square.x + ind != map_p.h_len && square.y + ind != map_p.v_len + && map[square.y + ind][square.x] != map_p.obstacle + && map[square.y][square.x + ind] != map_p.obstacle) + { + if (right_bottom_square_checker(square, ind, map, map_p)) + square.size = ind + 1; + else + return (square); + ind++; + } + return (square); +} + +t_square point_checker(char **map, t_map_property map_p) +{ + t_square big_square; + t_square new_square; + unsigned int ind_w; + unsigned int ind_h; + + ind_h = -1; + big_square.size = 0; + while (++ind_h != map_p.v_len) + { + ind_w = -1; + while (++ind_w != map_p.h_len) + { + init_t_squarre(&new_square, ind_w, ind_h, 0); + new_square = left_top_square_checker(new_square, map, map_p); + big_square = find_the_biggest_square(big_square, new_square); + } + } + return (big_square); +} + +/* + +#include + +int main(void) +{ +t_square coucou; + + +t_map_property map_p; + map_p.obstacle = 'o'; + map_p.clear = '.'; + map_p.full = 'x'; + map_p.v_len = 5; + map_p.h_len = 5; + +char *map[] = +{".o...", + "oo..o", + "..oo.", + ".....", + "..o.o"}; + + + +t_map_property map_p; + map_p.obstacle = 'o'; + map_p.clear = '.'; + map_p.full = 'x'; + map_p.v_len = 30; + map_p.h_len = 30; + +char *map[] = +{"o....oo...o.o.o..ooo...o....oo", + "...o..oo......oo.o..o......o.o", + "ooo........o..o.o..oo......ooo", + "o......oo...o....oooo..o....o.", + "......oo.........o..o.....o...", + ".o....o.......o.o.oooo...ooo..", + ".oo.o.oo.ooo.....oo.ooo.o.o.o.", + "oo...o.o...o..o.o..oooo....oo.", + "..ooo.oo....o..o.oo..o........", + "...o.oooo.....ooo..o........o.", + "o............oooo.o.o..oo.o.oo", + "o....o...oo....o.o....o.o.....", + "..o.o...o...oo..ooo......o....", + "o....o.........o...o....oo....", + "oo..o.......ooo...o...o.ooo.oo", + "o.o.....oo..oo.oo....o.oo.oo.o", + ".o.o..o.oo.oo..o.oo.oo.o.o.o.o", + ".o.o.....oo.o.o...o..o.oo....o", + "....o..oo..o...oo..o....o.o...", + "oo.o............o...o..oo..o..", + ".........o..o.oo..ooo..o..o..o", + "..o.ooooo...o.o...o.oo.o.o.ooo", + ".o....o...oooo..o......o.o....", + "o...ooo.....oo..o....o..ooo..o", + ".o...oo.o.....o.o.....o......o", + "o...oo.........o..o.......o...", + "oo.....oo.....o....oo.oo......", + ".........o......oo.o.oo.o.o.o.", + "o.o..o...o.o.....o.oo...oo..o.", + "..oo...o.oo.ooo..oo.o.o......o"}; + + +coucou = point_checker(map, map_p); +//replace_map(map, coucou, map_p); +printf ("%d\n", coucou.x); +printf ("%d\n", coucou.y); +printf ("%d\n", coucou.size); +//write_map(map, map_p); +} +*/ diff --git a/BSQ/find_square.o b/BSQ/find_square.o new file mode 100644 index 0000000..eea8fc4 Binary files /dev/null and b/BSQ/find_square.o differ diff --git a/BSQ/ft_atou.c b/BSQ/ft_atou.c new file mode 100644 index 0000000..4d9842e --- /dev/null +++ b/BSQ/ft_atou.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atou.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/02 11:44:05 by cchauvet #+# #+# */ +/* Updated: 2022/08/03 17:55:00 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_contain_only(char **lines, char *charset) +{ + int i; + int j; + int k; + + k = 0; + while (lines[k][0] != 0) + { + i = 0; + while (lines[k][i] != 0) + { + j = 0; + while (charset[j] != lines[k][i] && charset[j] != 0) + j++; + if (charset[j] == 0) + return (0); + i++; + } + k++; + } + return (1); +} diff --git a/BSQ/ft_contain_only.o b/BSQ/ft_contain_only.o new file mode 100644 index 0000000..aef8e08 Binary files /dev/null and b/BSQ/ft_contain_only.o differ diff --git a/BSQ/ft_duplicated.c b/BSQ/ft_duplicated.c new file mode 100644 index 0000000..acd558f --- /dev/null +++ b/BSQ/ft_duplicated.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_duplicated.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/02 10:41:19 by cchauvet #+# #+# */ +/* Updated: 2022/08/02 18:31:40 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_digit(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + { + if (!(str[i] >= '0' && str[i] <= '9')) + return (0); + i++; + } + return (1); +} diff --git a/BSQ/ft_is_digit.o b/BSQ/ft_is_digit.o new file mode 100644 index 0000000..3bb9c71 Binary files /dev/null and b/BSQ/ft_is_digit.o differ diff --git a/BSQ/ft_is_printable.c b/BSQ/ft_is_printable.c new file mode 100644 index 0000000..d742106 --- /dev/null +++ b/BSQ/ft_is_printable.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = 32 && *str <= 126)) + return (0); + str++; + } + return (1); +} diff --git a/BSQ/ft_is_printable.o b/BSQ/ft_is_printable.o new file mode 100644 index 0000000..94b29b2 Binary files /dev/null and b/BSQ/ft_is_printable.o differ diff --git a/BSQ/ft_mapcmp.c b/BSQ/ft_mapcmp.c new file mode 100644 index 0000000..d8ff908 --- /dev/null +++ b/BSQ/ft_mapcmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_mapcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/31 08:46:44 by nlauvray #+# #+# */ +/* Updated: 2022/08/02 18:38:07 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +void ft_putstr(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} diff --git a/BSQ/ft_putstr.o b/BSQ/ft_putstr.o new file mode 100644 index 0000000..3438636 Binary files /dev/null and b/BSQ/ft_putstr.o differ diff --git a/BSQ/ft_split.c b/BSQ/ft_split.c new file mode 100644 index 0000000..c779cbc --- /dev/null +++ b/BSQ/ft_split.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/31 08:41:20 by nlauvray #+# #+# */ +/* Updated: 2022/08/03 17:34:23 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +char **ft_split(char *str, char *sep) +{ + char **tab; + unsigned int i; + unsigned int j; + unsigned int k; + + i = 0; + j = 0; + tab = malloc(sizeof(str) * ft_strlen(str)); + while (str[i] != 0 && ft_strlen(str) > i) + { + k = i; + tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1)); + while (i < k + ft_strstr(&str[k], sep)) + { + tab[j][i - k] = str[i]; + i++; + } + tab[j][i - k] = '\0'; + i = k + ft_strstr(&str[k], sep) + ft_strlen(sep); + j++; + } + tab[j] = ""; + return (tab); +} diff --git a/BSQ/ft_split.o b/BSQ/ft_split.o new file mode 100644 index 0000000..f6b944d Binary files /dev/null and b/BSQ/ft_split.o differ diff --git a/BSQ/ft_strcat.c b/BSQ/ft_strcat.c new file mode 100644 index 0000000..652503b --- /dev/null +++ b/BSQ/ft_strcat.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/31 08:47:30 by nlauvray #+# #+# */ +/* Updated: 2022/08/02 14:29:35 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} diff --git a/BSQ/ft_strlen.o b/BSQ/ft_strlen.o new file mode 100644 index 0000000..d4853bb Binary files /dev/null and b/BSQ/ft_strlen.o differ diff --git a/BSQ/ft_strndup.c b/BSQ/ft_strndup.c new file mode 100644 index 0000000..58055a0 --- /dev/null +++ b/BSQ/ft_strndup.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strndup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/02 10:19:17 by cchauvet #+# #+# */ +/* Updated: 2022/08/02 14:24:27 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +char *ft_strndup(char *src, unsigned int n) +{ + char *dest; + unsigned int i; + + dest = malloc(sizeof(*src) * (ft_strlen(src) + 1)); + i = 0; + while (src[i] != 0 && i < n - 1) + { + dest[i] = src[i]; + i++; + } + dest[i] = 0; + return (dest); +} diff --git a/BSQ/ft_strndup.o b/BSQ/ft_strndup.o new file mode 100644 index 0000000..efa460c Binary files /dev/null and b/BSQ/ft_strndup.o differ diff --git a/BSQ/ft_strstr.c b/BSQ/ft_strstr.c new file mode 100644 index 0000000..9bb005d --- /dev/null +++ b/BSQ/ft_strstr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nlauvray +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/02 11:04:59 by cchauvet #+# #+# */ +/* Updated: 2022/08/02 14:30:16 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_tablen(char **tab) +{ + unsigned int i; + + i = 0; + while (tab[i][0] != 0) + i++; + return (i); +} diff --git a/BSQ/ft_tablen.o b/BSQ/ft_tablen.o new file mode 100644 index 0000000..9abe87e Binary files /dev/null and b/BSQ/ft_tablen.o differ diff --git a/BSQ/ft_write_map.c b/BSQ/ft_write_map.c new file mode 100644 index 0000000..17a298a --- /dev/null +++ b/BSQ/ft_write_map.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_write_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/02 11:30:49 by cchauvet #+# #+# */ +/* Updated: 2022/08/02 18:40:55 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +void write_map(char **map, t_map_property map_p) +{ + unsigned int x; + unsigned int y; + + y = -1; + while (++y != map_p.v_len) + { + x = -1; + while (++x != map_p.h_len) + write(1, map[y] + x, 1); + write(1, "\n", 1); + } +} + +void replace_map(char **map, t_square squarre, t_map_property map_p) +{ + int x; + int y; + + y = squarre.y - 1; + while (++y != squarre.size + squarre.y) + { + x = squarre.x - 1; + while (++x != squarre.size + squarre.x) + { + map[y][x] = map_p.full; + } + } +} diff --git a/BSQ/ft_write_map.o b/BSQ/ft_write_map.o new file mode 100644 index 0000000..a1d9104 Binary files /dev/null and b/BSQ/ft_write_map.o differ diff --git a/BSQ/main.c b/BSQ/main.c new file mode 100644 index 0000000..286bf02 --- /dev/null +++ b/BSQ/main.c @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/02 11:24:01 by lflandri #+# #+# */ +/* Updated: 2022/08/03 14:29:29 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +void free_map(char **map) +{ + char **map_adress; + + map -= 1; + map_adress = map; + while (**map != 0) + { + free(*map); + map++; + } + free(map_adress); +} + +void starting_crea_map(char *path, char *str) +{ + char **map; + t_map_property map_p_tempo; + t_map_property *map_p; + t_square square; + + map_p = &map_p_tempo; + if (str == NULL) + str = ft_filereader(path); + if (ft_strlen(str) <= 4) + { + free(str); + write(2, "map error\n", 10); + return ; + } + map = ft_atomap(str, map_p); + free(str); + if (map != NULL) + { + square = point_checker(map, *map_p); + replace_map(map, square, *map_p); + write_map(map, *map_p); + free_map(map); + } + else + write(2, "map error\n", 10); +} + +int main(int ac, char **av) +{ + int ind; + + if (ac != 1) + { + ind = 0; + while (++ind != ac) + { + starting_crea_map(av[ind], NULL); + if (ind + 1 != ac) + write(1, "\n", 1); + } + } + else + read_standart_entry(); + return (0); +} diff --git a/BSQ/main.o b/BSQ/main.o new file mode 100644 index 0000000..59dfe94 Binary files /dev/null and b/BSQ/main.o differ diff --git a/BSQ/map_reader.c b/BSQ/map_reader.c new file mode 100644 index 0000000..1fb6421 --- /dev/null +++ b/BSQ/map_reader.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map_reader.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/01 21:13:40 by cchauvet #+# #+# */ +/* Updated: 2022/08/03 17:57:26 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +t_map_property ft_map_error(void) +{ + t_map_property property; + + property.full = 0; + property.obstacle = 0; + property.clear = 0; + property.h_len = 0; + property.v_len = 0; + return (property); +} + +t_map_property property_return_error(char *lines_counter) +{ + free(lines_counter); + return (ft_map_error()); +} + +t_map_property ft_get_map_property(char **lines) +{ + t_map_property property; + char *lines_counter; + unsigned int i; + + if (!(ft_strlen(lines[0]) >= 4) + || !ft_is_printable(&lines[0][ft_strlen(lines[0]) - 3]) + || ft_duplicated(&lines[0][ft_strlen(lines[0]) - 3])) + return (ft_map_error()); + lines_counter = ft_strndup(lines[0], ft_strlen(lines[0]) - 2); + if (!ft_is_digit(lines_counter)) + return (property_return_error(lines_counter)); + if (ft_tablen(&lines[1]) != ft_atou(lines_counter)) + return (property_return_error(lines_counter)); + i = 2; + while (ft_strlen(lines[1]) == ft_strlen(lines[i])) + i++; + if (i != ft_tablen(lines)) + return (property_return_error(lines_counter)); + property.full = lines[0][ft_strlen(lines[0]) - 1]; + property.obstacle = lines[0][ft_strlen(lines[0]) - 2]; + property.clear = lines[0][ft_strlen(lines[0]) - 3]; + property.v_len = ft_atou(lines_counter); + property.h_len = ft_strlen(lines[1]); + free(lines_counter); + return (property); +} + +char **ft_atomap(char *str, t_map_property *property) +{ + char **lines; + + lines = ft_split(str, "\n"); + *property = ft_get_map_property(lines); + if (ft_mapcmp(*property, ft_map_error()) != 0) + { + free_map(&lines[1]); + return (NULL); + } + lines[0][ft_strlen(lines[0]) - 1] = 0; + if (ft_contain_only(&lines[1], &lines[0][ft_strlen(lines[0]) - 2]) == 0) + { + free_map(&lines[1]); + return (NULL); + } + return (&lines[1]); +} diff --git a/BSQ/map_reader.o b/BSQ/map_reader.o new file mode 100644 index 0000000..8b1d417 Binary files /dev/null and b/BSQ/map_reader.o differ diff --git a/BSQ/maps b/BSQ/maps new file mode 100644 index 0000000..b8b2cf7 --- /dev/null +++ b/BSQ/maps @@ -0,0 +1,2 @@ +1_dp +_d____________________________________________________________________________________ diff --git a/BSQ/standart_entry_reader.c b/BSQ/standart_entry_reader.c new file mode 100644 index 0000000..d12853c --- /dev/null +++ b/BSQ/standart_entry_reader.c @@ -0,0 +1,105 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* standart_entry_reader.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/03 08:52:24 by lflandri #+# #+# */ +/* Updated: 2022/08/03 18:08:16 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" + +char *add_to_malloc(char *mal, char *str) +{ + char *new_mal; + int ind; + + ind = 0; + while (mal[ind]) + ind++; + new_mal = malloc(sizeof(char) * (ind + 2)); + ind = -1; + while (mal[++ind]) + new_mal[ind] = mal[ind]; + new_mal[ind] = *str; + new_mal[ind + 1] = 0; + free(mal); + return (new_mal); +} + +void read_map_on_entry(char *mal, unsigned int lines_counter) +{ + char str[1]; + unsigned int count; + + count = 0; + if (!lines_counter) + { + free(mal); + write(2, "map error\n", 10); + return ; + } + mal = add_to_malloc(mal, "\n"); + while (count != lines_counter) + { + read(STDIN_FILENO, str, 1); + if (*str == '\n') + count++; + mal = add_to_malloc(mal, str); + } + write(1, "\n", 1); + starting_crea_map(NULL, mal); +} + +void check_read_map_on_entry(char *mal) +{ + char *lines_counter; + + if (!(ft_strlen(mal) >= 4)) + { + free(mal); + write(2, "map error\n", 10); + return ; + } + lines_counter = ft_strndup(mal, ft_strlen(mal) - 2); + if (!ft_is_digit(lines_counter)) + { + free(mal); + free(lines_counter); + write(2, "map error\n", 10); + return ; + } + read_map_on_entry(mal, ft_atou(lines_counter)); + free(lines_counter); +} + +void read_standart_entry(void) +{ + char str[1]; + char *mal; + int size; + int fd; + + mal = malloc(sizeof(char)); + *mal = '\0'; + size = 1; + while (size == 1) + { + size = read(STDIN_FILENO, str, 1); + if (*str == '\n') + break ; + mal = add_to_malloc(mal, str); + } + fd = open(mal, O_RDONLY); + if (fd != -1) + { + close(fd); + starting_crea_map(mal, NULL); + free(mal); + } + else + check_read_map_on_entry(mal); +} diff --git a/BSQ/standart_entry_reader.o b/BSQ/standart_entry_reader.o new file mode 100644 index 0000000..675be8d Binary files /dev/null and b/BSQ/standart_entry_reader.o differ diff --git a/C/c00/ex00/ft_putchar.c b/C/c00/ex00/ft_putchar.c new file mode 100644 index 0000000..ddcb164 --- /dev/null +++ b/C/c00/ex00/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:47:36 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:39:47 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/C/c00/ex01/ft_print_alphabet.c b/C/c00/ex01/ft_print_alphabet.c new file mode 100644 index 0000000..08d6d65 --- /dev/null +++ b/C/c00/ex01/ft_print_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:49:41 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:42:13 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_alphabet(void) +{ + char a; + + a = 'a'; + while ('z' >= a) + { + write(1, &a, 1); + a++; + } +} diff --git a/C/c00/ex02/.ft_print_reverse_alphabet.c.swp b/C/c00/ex02/.ft_print_reverse_alphabet.c.swp new file mode 100644 index 0000000..7836f7f Binary files /dev/null and b/C/c00/ex02/.ft_print_reverse_alphabet.c.swp differ diff --git a/C/c00/ex02/ft_print_reverse_alphabet.c b/C/c00/ex02/ft_print_reverse_alphabet.c new file mode 100644 index 0000000..605eb35 --- /dev/null +++ b/C/c00/ex02/ft_print_reverse_alphabet.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_reverse_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:52:57 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 13:54:25 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_print_alphabet(void) +{ + char a; + + a = 'z'; + while (a >= 'a') + { + write(1, &a, 1); + a--; + } +} diff --git a/C/c00/ex03/ft_print_numbers.c b/C/c00/ex03/ft_print_numbers.c new file mode 100644 index 0000000..52a4f91 --- /dev/null +++ b/C/c00/ex03/ft_print_numbers.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_numbers.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:55:25 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:45:15 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_numbers(void) +{ + char a; + + a = '0'; + while ('9' >= a) + { + write(1, &a, 1); + a++; + } +} diff --git a/C/c00/ex04/ft_is_negative.c b/C/c00/ex04/ft_is_negative.c new file mode 100644 index 0000000..3b912e6 --- /dev/null +++ b/C/c00/ex04/ft_is_negative.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_negative.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 14:14:39 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:51:31 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_is_negative(int n) +{ + char a; + + a = 'N'; + if (n > 0) + { + a = 'P'; + } + write(1, &a, 1); +} diff --git a/C/c00/ex05/ft_print_comb.c b/C/c00/ex05/ft_print_comb.c new file mode 100644 index 0000000..c9af0f6 --- /dev/null +++ b/C/c00/ex05/ft_print_comb.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_comb.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 14:18:48 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 15:10:35 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_result(char x, char y, char z) +{ + ft_putchar(x); + ft_putchar(y); + ft_putchar(z); + if (!((x == '7') && (y == '8') && (z == '9'))) + { + ft_putchar(','); + ft_putchar(' '); + } +} + +void ft_print_comb(void) +{ + char x; + char y; + char z; + + x = '0'; + while (x <= '7') + { + y = x + 1; + while (y <= '8') + { + z = y + 1; + while (z <= '9') + { + ft_result(x, y, z); + z++; + } + y++; + } + x++; + } +} diff --git a/C/c00/ex06/ft_print_comb2.c b/C/c00/ex06/ft_print_comb2.c new file mode 100644 index 0000000..06d5695 --- /dev/null +++ b/C/c00/ex06/ft_print_comb2.c @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_comb2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +bool ft_sames(char a, char b, char c, char d) +{ + char e; + + b = a; + if (e != b) + return (false); + e = b; + if (e != c) + return (false); + e = c; + if (e != d) + return (false); + return (true); +} + +void ft_result(char a, char b, char c, char d) +{ + if (!ft_sames(a, b, c, d)) + { + ft_putchar(a); + ft_putchar(b); + ft_putchar(' '); + ft_putchar(c); + ft_putchar(d); + if (!((a == '9') && (b == '8') && (c == '9') && (d == '9'))) + { + ft_putchar(','); + ft_putchar(' '); + } + } +} + +void ft_print_comb2(void) +{ + char a; + char b; + char c; + char d; + + a = '0'; + while (a <= '9') + { + b = '0'; + while (b <= '8') + { + c = '0'; + while (c <= '9') + { + d = '0'; + while (d <= '9') + { + ft_result(a, b, c, d++); + } + c++; + } + b++; + } + a++; + } +} diff --git a/C/c00/ex07/ft_putnbr.c b/C/c00/ex07/ft_putnbr.c new file mode 100644 index 0000000..c5945b3 --- /dev/null +++ b/C/c00/ex07/ft_putnbr.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char a) +{ + write(1, &a, 1); +} + +void ft_putnbr(int nb) +{ + if (nb < 0) + { + ft_putchar('-'); + ft_putnbr(-nb); + } + else if (nb > 10) + { + ft_putnbr(nb / 10); + ft_putchar(nb % 10 + 48); + } + else + { + ft_putchar(nb + 48); + } +} diff --git a/C/c00/ex08/ft_print_combn.c b/C/c00/ex08/ft_print_combn.c new file mode 100644 index 0000000..5da2564 --- /dev/null +++ b/C/c00/ex08/ft_print_combn.c @@ -0,0 +1,4 @@ +void ft_print_combn(int n) +{ + +} diff --git a/C/c00v2/ex00/ft_putchar.c b/C/c00v2/ex00/ft_putchar.c new file mode 100644 index 0000000..ddcb164 --- /dev/null +++ b/C/c00v2/ex00/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:47:36 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:39:47 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/C/c00v2/ex01/ft_print_alphabet.c b/C/c00v2/ex01/ft_print_alphabet.c new file mode 100644 index 0000000..08d6d65 --- /dev/null +++ b/C/c00v2/ex01/ft_print_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:49:41 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:42:13 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_alphabet(void) +{ + char a; + + a = 'a'; + while ('z' >= a) + { + write(1, &a, 1); + a++; + } +} diff --git a/C/c00v2/ex02/ft_print_reverse_alphabet.c b/C/c00v2/ex02/ft_print_reverse_alphabet.c new file mode 100644 index 0000000..c4510da --- /dev/null +++ b/C/c00v2/ex02/ft_print_reverse_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_reverse_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:52:57 by cchauvet #+# #+# */ +/* Updated: 2022/07/16 10:37:57 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_alphabet(void) +{ + char a; + + a = 'z'; + while (a >= 'a') + { + write(1, &a, 1); + a--; + } +} diff --git a/C/c00v2/ex03/ft_print_numbers.c b/C/c00v2/ex03/ft_print_numbers.c new file mode 100644 index 0000000..52a4f91 --- /dev/null +++ b/C/c00v2/ex03/ft_print_numbers.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_numbers.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:55:25 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:45:15 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_numbers(void) +{ + char a; + + a = '0'; + while ('9' >= a) + { + write(1, &a, 1); + a++; + } +} diff --git a/C/c00v2/ex04/ft_is_negative.c b/C/c00v2/ex04/ft_is_negative.c new file mode 100644 index 0000000..514f189 --- /dev/null +++ b/C/c00v2/ex04/ft_is_negative.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_negative.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 14:14:39 by cchauvet #+# #+# */ +/* Updated: 2022/07/16 10:38:55 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_is_negative(int n) +{ + char a; + + a = 'N'; + if (n >= 0) + { + a = 'P'; + } + write(1, &a, 1); +} diff --git a/C/c00v2/ex05/ft_print_comb.c b/C/c00v2/ex05/ft_print_comb.c new file mode 100644 index 0000000..c9af0f6 --- /dev/null +++ b/C/c00v2/ex05/ft_print_comb.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_comb.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 14:18:48 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 15:10:35 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_result(char x, char y, char z) +{ + ft_putchar(x); + ft_putchar(y); + ft_putchar(z); + if (!((x == '7') && (y == '8') && (z == '9'))) + { + ft_putchar(','); + ft_putchar(' '); + } +} + +void ft_print_comb(void) +{ + char x; + char y; + char z; + + x = '0'; + while (x <= '7') + { + y = x + 1; + while (y <= '8') + { + z = y + 1; + while (z <= '9') + { + ft_result(x, y, z); + z++; + } + y++; + } + x++; + } +} diff --git a/C/c00v2/ex07/ft_putnbr.c b/C/c00v2/ex07/ft_putnbr.c new file mode 100644 index 0000000..c5945b3 --- /dev/null +++ b/C/c00v2/ex07/ft_putnbr.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char a) +{ + write(1, &a, 1); +} + +void ft_putnbr(int nb) +{ + if (nb < 0) + { + ft_putchar('-'); + ft_putnbr(-nb); + } + else if (nb > 10) + { + ft_putnbr(nb / 10); + ft_putchar(nb % 10 + 48); + } + else + { + ft_putchar(nb + 48); + } +} diff --git a/C/c00v3/ex00/ft_putchar.c b/C/c00v3/ex00/ft_putchar.c new file mode 100644 index 0000000..ddcb164 --- /dev/null +++ b/C/c00v3/ex00/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:47:36 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:39:47 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/C/c00v3/ex01/ft_print_alphabet.c b/C/c00v3/ex01/ft_print_alphabet.c new file mode 100644 index 0000000..08d6d65 --- /dev/null +++ b/C/c00v3/ex01/ft_print_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:49:41 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:42:13 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_alphabet(void) +{ + char a; + + a = 'a'; + while ('z' >= a) + { + write(1, &a, 1); + a++; + } +} diff --git a/C/c00v3/ex02/ft_print_reverse_alphabet.c b/C/c00v3/ex02/ft_print_reverse_alphabet.c new file mode 100644 index 0000000..551100a --- /dev/null +++ b/C/c00v3/ex02/ft_print_reverse_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_reverse_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:52:57 by cchauvet #+# #+# */ +/* Updated: 2022/07/17 13:07:32 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_reverse_alphabet(void) +{ + char a; + + a = 'z'; + while (a >= 'a') + { + write(1, &a, 1); + a--; + } +} diff --git a/C/c00v3/ex03/ft_print_numbers.c b/C/c00v3/ex03/ft_print_numbers.c new file mode 100644 index 0000000..52a4f91 --- /dev/null +++ b/C/c00v3/ex03/ft_print_numbers.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_numbers.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 13:55:25 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 14:45:15 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_print_numbers(void) +{ + char a; + + a = '0'; + while ('9' >= a) + { + write(1, &a, 1); + a++; + } +} diff --git a/C/c00v3/ex04/ft_is_negative.c b/C/c00v3/ex04/ft_is_negative.c new file mode 100644 index 0000000..514f189 --- /dev/null +++ b/C/c00v3/ex04/ft_is_negative.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_negative.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 14:14:39 by cchauvet #+# #+# */ +/* Updated: 2022/07/16 10:38:55 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_is_negative(int n) +{ + char a; + + a = 'N'; + if (n >= 0) + { + a = 'P'; + } + write(1, &a, 1); +} diff --git a/C/c00v3/ex05/ft_print_comb.c b/C/c00v3/ex05/ft_print_comb.c new file mode 100644 index 0000000..c9af0f6 --- /dev/null +++ b/C/c00v3/ex05/ft_print_comb.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_comb.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/14 14:18:48 by cchauvet #+# #+# */ +/* Updated: 2022/07/14 15:10:35 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_result(char x, char y, char z) +{ + ft_putchar(x); + ft_putchar(y); + ft_putchar(z); + if (!((x == '7') && (y == '8') && (z == '9'))) + { + ft_putchar(','); + ft_putchar(' '); + } +} + +void ft_print_comb(void) +{ + char x; + char y; + char z; + + x = '0'; + while (x <= '7') + { + y = x + 1; + while (y <= '8') + { + z = y + 1; + while (z <= '9') + { + ft_result(x, y, z); + z++; + } + y++; + } + x++; + } +} diff --git a/C/c00v3/ex07/ft_putnbr.c b/C/c00v3/ex07/ft_putnbr.c new file mode 100644 index 0000000..c5945b3 --- /dev/null +++ b/C/c00v3/ex07/ft_putnbr.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char a) +{ + write(1, &a, 1); +} + +void ft_putnbr(int nb) +{ + if (nb < 0) + { + ft_putchar('-'); + ft_putnbr(-nb); + } + else if (nb > 10) + { + ft_putnbr(nb / 10); + ft_putchar(nb % 10 + 48); + } + else + { + ft_putchar(nb + 48); + } +} diff --git a/C/c01/ex00/ft_ft.c b/C/c01/ex00/ft_ft.c new file mode 100644 index 0000000..eab8124 --- /dev/null +++ b/C/c01/ex00/ft_ft.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/C/c01/ex01/ft_ultimate_ft.c b/C/c01/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..fbcf4f0 --- /dev/null +++ b/C/c01/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + { + write(1, str++, 1); + } +} diff --git a/C/c01/ex06/ft_strlen.c b/C/c01/ex06/ft_strlen.c new file mode 100644 index 0000000..43ede93 --- /dev/null +++ b/C/c01/ex06/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int a; + + a = 0; + while (*str != 0) + { + a++; + str++; + } + return(a); +} diff --git a/C/c01/ex07/ft_rev_int_tab.c b/C/c01/ex07/ft_rev_int_tab.c new file mode 100644 index 0000000..cf9c621 --- /dev/null +++ b/C/c01/ex07/ft_rev_int_tab.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_int_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/C/c01v1/ex01/ft_ultimate_ft.c b/C/c01v1/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..fbcf4f0 --- /dev/null +++ b/C/c01v1/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + { + write(1, str++, 1); + } +} diff --git a/C/c01v1/ex06/ft_strlen.c b/C/c01v1/ex06/ft_strlen.c new file mode 100644 index 0000000..43ede93 --- /dev/null +++ b/C/c01v1/ex06/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int a; + + a = 0; + while (*str != 0) + { + a++; + str++; + } + return(a); +} diff --git a/C/c01v1/ex07/ft_rev_int_tab.c b/C/c01v1/ex07/ft_rev_int_tab.c new file mode 100644 index 0000000..cf9c621 --- /dev/null +++ b/C/c01v1/ex07/ft_rev_int_tab.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_int_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/C/c01v2/ex01/ft_ultimate_ft.c b/C/c01v2/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..fbcf4f0 --- /dev/null +++ b/C/c01v2/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + { + write(1, str++, 1); + } +} diff --git a/C/c01v2/ex06/ft_strlen.c b/C/c01v2/ex06/ft_strlen.c new file mode 100644 index 0000000..dd3200e --- /dev/null +++ b/C/c01v2/ex06/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int a; + + a = 0; + while (*str != 0) + { + a++; + str++; + } + return (a); +} diff --git a/C/c01v2/ex07/ft_rev_int_tab.c b/C/c01v2/ex07/ft_rev_int_tab.c new file mode 100644 index 0000000..cf9c621 --- /dev/null +++ b/C/c01v2/ex07/ft_rev_int_tab.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_int_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/C/c01v3/ex01/ft_ultimate_ft.c b/C/c01v3/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..fbcf4f0 --- /dev/null +++ b/C/c01v3/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + { + write(1, str++, 1); + } +} diff --git a/C/c01v3/ex06/ft_strlen.c b/C/c01v3/ex06/ft_strlen.c new file mode 100644 index 0000000..e065d1e --- /dev/null +++ b/C/c01v3/ex06/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_sort_int_tab(int *tab, int size) +{ + int i; + int j; + int tempo; + + i = 0; + while (i < size) + { + j = 0; + while (j < size - 1) + { + if (tab[j] > tab[j + 1]) + { + tempo = tab[j]; + tab[j] = tab[j + 1]; + tab[j + 1] = tempo; + } + j++; + } + i++; + } +} +/* +#include +int main() +{ + int tab[] = {6,5,4,3,2,1}; + int i = 0; + + ft_sort_int_tab(tab, 6); + while (i < 6) + { + printf("%d,", tab[i]); + i++; + } +} +*/ diff --git a/C/c02/ex00/ft_strcpy.c b/C/c02/ex00/ft_strcpy.c new file mode 100644 index 0000000..2074a77 --- /dev/null +++ b/C/c02/ex00/ft_strcpy.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main(void) +{ + char dest1[10]; + char src1[10] = "test"; + + strcpy(dest1, src1); + + printf("%s", dest1); + + + printf("\n"); + + + char dest2[10]; + char src2[10] = "test"; + + ft_strcpy(dest2, src2); + + printf("%s", dest2); +} +*/ diff --git a/C/c02/ex01/strncpy.c b/C/c02/ex01/strncpy.c new file mode 100644 index 0000000..223e269 --- /dev/null +++ b/C/c02/ex01/strncpy.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main(void) +{ + char dest1[10]; + char src1[10] = "test"; + + strncpy(dest1, src1, 2); + + printf("%s", dest1); + + + printf("\n"); + + + char dest2[10]; + char src2[10] = "test"; + + ft_strncpy(dest2, src2, 2); + + printf("%s", dest2); +} +*/ diff --git a/C/c02/ex02/ft_str_is_alpha.c b/C/c02/ex02/ft_str_is_alpha.c new file mode 100644 index 0000000..ab5c191 --- /dev/null +++ b/C/c02/ex02/ft_str_is_alpha.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} + +/* +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main(void) +{ + ft_putchar(ft_str_is_alpha("ff")+'0'); + ft_putchar(ft_str_is_alpha("dfdf5f")+'0'); + ft_putchar(ft_str_is_alpha("GDGFSGF")+48); + ft_putchar(ft_str_is_alpha("FG5DG")+48); + ft_putchar(ft_str_is_alpha("")+48); +} +*/ diff --git a/C/c02/ex03/ft_str_is_numeric.c b/C/c02/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..da8b55d --- /dev/null +++ b/C/c02/ex03/ft_str_is_numeric.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} + +/* +void ft_putchar(char c) +{ + write(1, &c, 1); +} +int main() +{ + ft_putchar(ft_str_is_numeric("55654")+48); + ft_putchar(ft_str_is_numeric("ssdf5")+48); + ft_putchar(ft_str_is_numeric("5")+48); + ft_putchar(ft_str_is_numeric("55d654")+48); + ft_putchar(ft_str_is_numeric("")+48); +} +*/ diff --git a/C/c02/ex04/ft_str_is_lowercase.c b/C/c02/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..649e51a --- /dev/null +++ b/C/c02/ex04/ft_str_is_lowercase.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = 'a' && str[i] <= 'z') + str[i] -= 32; + i++; + } + return (str); +} + +/* +#include + +int main() +{ + char str[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un"; + printf("%s\n", ft_strcapitalize(str)); + printf("Salut, Comment Tu Vas ? 42mots Quarante-Deux; Cinquante+Et+Un"); +} +*/ diff --git a/C/c02v1/ex00/ft_strcpy.c b/C/c02v1/ex00/ft_strcpy.c new file mode 100644 index 0000000..1fd4e6b --- /dev/null +++ b/C/c02v1/ex00/ft_strcpy.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} diff --git a/C/c02v1/ex03/ft_str_is_numeric.c b/C/c02v1/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..daeba52 --- /dev/null +++ b/C/c02v1/ex03/ft_str_is_numeric.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} diff --git a/C/c02v1/ex04/ft_str_is_lowercase.c b/C/c02v1/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..cc4e5aa --- /dev/null +++ b/C/c02v1/ex04/ft_str_is_lowercase.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int main() +{ + char str[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un"; + printf("%s\n", str); + printf("%s", ft_strcapitalize(str)); +} +*/ diff --git a/C/c02v2/ex00/ft_strcpy.c b/C/c02v2/ex00/ft_strcpy.c new file mode 100644 index 0000000..3ef6ca9 --- /dev/null +++ b/C/c02v2/ex00/ft_strcpy.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} diff --git a/C/c02v2/ex03/ft_str_is_numeric.c b/C/c02v2/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..daeba52 --- /dev/null +++ b/C/c02v2/ex03/ft_str_is_numeric.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} diff --git a/C/c02v2/ex04/ft_str_is_lowercase.c b/C/c02v2/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..cc4e5aa --- /dev/null +++ b/C/c02v2/ex04/ft_str_is_lowercase.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} diff --git a/C/c02v3/ex03/ft_str_is_numeric.c b/C/c02v3/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..daeba52 --- /dev/null +++ b/C/c02v3/ex03/ft_str_is_numeric.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} diff --git a/C/c02v3/ex04/ft_str_is_lowercase.c b/C/c02v3/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..cc4e5aa --- /dev/null +++ b/C/c02v3/ex04/ft_str_is_lowercase.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} diff --git a/C/c02v4/ex03/ft_str_is_numeric.c b/C/c02v4/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..daeba52 --- /dev/null +++ b/C/c02v4/ex03/ft_str_is_numeric.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} diff --git a/C/c02v4/ex04/ft_str_is_lowercase.c b/C/c02v4/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..cc4e5aa --- /dev/null +++ b/C/c02v4/ex04/ft_str_is_lowercase.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int main() +{ + printf("%d", ft_strlen("123456789")); + printf("%d", ft_strlen("")); +} +*/ diff --git a/C/c04/ex01/ft_putstr.c b/C/c04/ex01/ft_putstr.c new file mode 100644 index 0000000..72a05fe --- /dev/null +++ b/C/c04/ex01/ft_putstr.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +/* +int main() +{ + ft_putstr("test"); +} +*/ diff --git a/C/c04/ex02/ft_putnbr.c b/C/c04/ex02/ft_putnbr.c new file mode 100644 index 0000000..f105517 --- /dev/null +++ b/C/c04/ex02/ft_putnbr.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr(int nbr) +{ + if (nbr == -2147483648) + { + ft_putnbr(-2); + ft_putnbr(147483648); + } + else if (nbr < 0) + { + ft_putchar('-'); + ft_putnbr(-nbr); + } + else if (nbr > 9) + { + ft_putnbr(nbr / 10); + ft_putnbr(nbr % 10); + } + else + { + ft_putchar(nbr + 48); + } +} + +/* +int main() +{ + ft_putnbr(-2147483648); +} +*/ diff --git a/C/c04/ex03/ft_atoi.c b/C/c04/ex03/ft_atoi.c new file mode 100644 index 0000000..5c73bdd --- /dev/null +++ b/C/c04/ex03/ft_atoi.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0' && str[i] <= '9') + { + nbr = (nbr * 10 + (str[i] - '0')); + i++; + } + return (nbr * sign); +} + +/* +#include + +int main() +{ + printf("%d", ft_atoi("---+--+1234ab567")); +} +*/ diff --git a/C/c04/ex04/ft_putnbr_base.c b/C/c04/ex04/ft_putnbr_base.c new file mode 100644 index 0000000..ce6bf3f --- /dev/null +++ b/C/c04/ex04/ft_putnbr_base.c @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_baser(char *str) +{ + int i; + int j; + int count; + + i = -1; + while (str[++i] != 0) + { + count = 0; + j = 0; + while (str[j] != 0) + { + if (str[i] == str[j]) + count++; + j++; + } + if (count > 1) + return (0); + if (str[i] == '+') + return (0); + if (str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +void ft_put(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr_base(int nbr, char *base) +{ + int base_size; + + base_size = ft_baser(base); + if (base_size == 0) + return (); + if (nbr == -2147483648) + { + ft_putnbr_base(-2, base); + ft_putnbr_base(147483648, base); + } + else if (nbr < 0) + { + ft_put('-'); + ft_putnbr_base(-nbr, base); + } + else if (nbr > base_size - 1) + { + ft_putnbr_base(nbr / base_size, base); + ft_putnbr_base(nbr % base_size, base); + } + else + ft_put(base[nbr]); +} +/* +#include + +int main(void) +{ + ft_putnbr_base(128, "01"); +} +*/ diff --git a/C/c04/ex05/ft_atoi_base.c b/C/c04/ex05/ft_atoi_base.c new file mode 100644 index 0000000..cb76138 --- /dev/null +++ b/C/c04/ex05/ft_atoi_base.c @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 1 || str[i] == '+' || str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +int ft_find(char *str, char to_find) +{ + int i; + + i = 0; + while (str[i] != 0) + { + if (str[i] == to_find) + return (i); + i++; + } + return (-1); +} + +int ft_atoi_base(char *str, char *base) +{ + int base_size; + int sign; + int nbr; + int i; + + nbr = 0; + sign = 1; + base_size = ft_baser(base); + i = 0; + if (base == 0) + return (0); + while (str[i] == '+' || str[i] == '-' || str[i] == ' ') + if (str[i++] == '-') + sign = sign * -1; + while (ft_find(base, str[i]) != -1) + { + nbr = nbr * base_size + ft_find(base, str[i]); + str++; + } + return (nbr * sign); +} +/* +#include + +int main() +{ + printf("%d", ft_atoi_base(" ++----10gdg", "01")); +} +*/ diff --git a/C/c04v1/ex00/ft_strlen.c b/C/c04v1/ex00/ft_strlen.c new file mode 100644 index 0000000..f890f87 --- /dev/null +++ b/C/c04v1/ex00/ft_strlen.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} diff --git a/C/c04v1/ex02/ft_putnbr.c b/C/c04v1/ex02/ft_putnbr.c new file mode 100644 index 0000000..7cf66ff --- /dev/null +++ b/C/c04v1/ex02/ft_putnbr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr(int nbr) +{ + if (nbr == -2147483648) + { + ft_putnbr(-2); + ft_putnbr(147483648); + } + else if (nbr < 0) + { + ft_putchar('-'); + ft_putnbr(-nbr); + } + else if (nbr > 9) + { + ft_putnbr(nbr / 10); + ft_putnbr(nbr % 10); + } + else + { + ft_putchar(nbr + 48); + } +} diff --git a/C/c04v1/ex03/ft_atoi.c b/C/c04v1/ex03/ft_atoi.c new file mode 100644 index 0000000..961ebd3 --- /dev/null +++ b/C/c04v1/ex03/ft_atoi.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0' && str[i] <= '9') + { + nbr = (nbr * 10 + (str[i] - '0')); + i++; + } + return (nbr * sign); +} diff --git a/C/c04v1/ex04/ft_putnbr_base.c b/C/c04v1/ex04/ft_putnbr_base.c new file mode 100644 index 0000000..22f72de --- /dev/null +++ b/C/c04v1/ex04/ft_putnbr_base.c @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_baser(char *str) +{ + int i; + int j; + int count; + + i = -1; + while (str[++i] != 0) + { + count = 0; + j = 0; + while (str[j] != 0) + { + if (str[i] == str[j]) + count++; + j++; + } + if (count > 1) + return (0); + if (str[i] == '+') + return (0); + if (str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +void ft_put(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr_base(int nbr, char *base) +{ + int base_size; + + base_size = ft_baser(base); + if (base_size == 0) + return (); + if (nbr == -2147483648) + { + ft_putnbr_base(-2, base); + ft_putnbr_base(147483648, base); + } + else if (nbr < 0) + { + ft_put('-'); + ft_putnbr_base(-nbr, base); + } + else if (nbr > base_size - 1) + { + ft_putnbr_base(nbr / base_size, base); + ft_putnbr_base(nbr % base_size, base); + } + else + ft_put(base[nbr]); +} diff --git a/C/c04v1/ex05/ft_atoi_base.c b/C/c04v1/ex05/ft_atoi_base.c new file mode 100644 index 0000000..8959708 --- /dev/null +++ b/C/c04v1/ex05/ft_atoi_base.c @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 1 || str[i] == '+' || str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +int ft_find(char *str, char to_find) +{ + int i; + + i = 0; + while (str[i] != 0) + { + if (str[i] == to_find) + return (i); + i++; + } + return (-1); +} + +int ft_atoi_base(char *str, char *base) +{ + int base_size; + int sign; + int nbr; + int i; + + nbr = 0; + sign = 1; + base_size = ft_baser(base); + i = 0; + if (base == 0) + return (0); + while (str[i] != ' ') + i++; + while (str[i] == '+' || str[i] == '-') + if (str[i++] == '-') + sign = sign * -1; + while (ft_find(base, str[i]) != -1) + { + nbr = nbr * base_size + ft_find(base, str[i]); + str++; + } + return (nbr * sign); +} diff --git a/C/c04v2/ex00/ft_strlen.c b/C/c04v2/ex00/ft_strlen.c new file mode 100644 index 0000000..f890f87 --- /dev/null +++ b/C/c04v2/ex00/ft_strlen.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} diff --git a/C/c04v2/ex02/ft_putnbr.c b/C/c04v2/ex02/ft_putnbr.c new file mode 100644 index 0000000..7cf66ff --- /dev/null +++ b/C/c04v2/ex02/ft_putnbr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr(int nbr) +{ + if (nbr == -2147483648) + { + ft_putnbr(-2); + ft_putnbr(147483648); + } + else if (nbr < 0) + { + ft_putchar('-'); + ft_putnbr(-nbr); + } + else if (nbr > 9) + { + ft_putnbr(nbr / 10); + ft_putnbr(nbr % 10); + } + else + { + ft_putchar(nbr + 48); + } +} diff --git a/C/c04v2/ex03/a.out b/C/c04v2/ex03/a.out new file mode 100755 index 0000000..1c9ea66 Binary files /dev/null and b/C/c04v2/ex03/a.out differ diff --git a/C/c04v2/ex03/ft_atoi.c b/C/c04v2/ex03/ft_atoi.c new file mode 100644 index 0000000..6d9b842 --- /dev/null +++ b/C/c04v2/ex03/ft_atoi.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0' && str[i] <= '9') + { + nbr = nbr * 10 + str[i] - '0'; + i++; + } + return (nbr * sign); +} + +#include + +int main () +{ + printf("%d", ft_atoi(" +--+-++--00000132563hhi2167")); +} + diff --git a/C/c04v2/ex04/a.out b/C/c04v2/ex04/a.out new file mode 100755 index 0000000..1025a16 Binary files /dev/null and b/C/c04v2/ex04/a.out differ diff --git a/C/c04v2/ex04/ft_putnbr_base.c b/C/c04v2/ex04/ft_putnbr_base.c new file mode 100644 index 0000000..7ff78da --- /dev/null +++ b/C/c04v2/ex04/ft_putnbr_base.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_baser(char *str) +{ + int i; + int j; + int count; + + i = -1; + while (str[++i] != 0) + { + count = 0; + j = 0; + while (str[j] != 0) + { + if (str[i] == str[j]) + count++; + j++; + } + if (count > 1) + return (0); + if (str[i] == '+') + return (0); + if (str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr_base(int nbr, char *base) +{ + int base_size; + + base_size = ft_baser(base); + if (base_size == 0) + return ; + if (nbr == -2147483648) + { + ft_putnbr_base(-2, base); + ft_putnbr_base(147483648, base); + } + else if (nbr < 0) + { + ft_putchar('-'); + ft_putnbr_base(-nbr, base); + } + else if (nbr > base_size - 1) + { + ft_putnbr_base(nbr / base_size, base); + ft_putnbr_base(nbr % base_size, base); + } + else + ft_putchar(base[nbr]); +} + +int main () +{ + ft_putnbr_base(15, "01"); +} diff --git a/C/c04v2/ex05/ft_atoi_base.c b/C/c04v2/ex05/ft_atoi_base.c new file mode 100644 index 0000000..9d8698c --- /dev/null +++ b/C/c04v2/ex05/ft_atoi_base.c @@ -0,0 +1,94 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 1 || str[i] == '+' || str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +int ft_find(char *str, char to_find) +{ + int i; + + i = 0; + while (str[i] != 0) + { + if (str[i] == to_find) + return (i); + i++; + } + return (-1); +} + +int ft_whitespaces(char *str) +{ + char *space; + int j; + int i; + + space = "\n\r\v\t\n "; + i = 0; + j = 0; + while (space[i] != 0) + { + while (str[j] == space[i]) + { + if (str[j] == 0) + return (j); + i = 0; + j++; + } + i++; + } + return (j); +} + +int ft_atoi_base(char *str, char *base) +{ + int base_size; + int sign; + int nbr; + int i; + + nbr = 0; + sign = 1; + base_size = ft_baser(base); + if (base == 0) + return (0); + i = ft_whitespaces(str); + while (str[i] == '+' || str[i] == '-') + if (str[i++] == '-') + sign = sign * -1; + while (ft_find(base, str[i]) != -1) + { + nbr = nbr * base_size + ft_find(base, str[i]); + str++; + } + return (nbr * sign); +} diff --git a/C/c05/ex00/ft_iterative_factorial.c b/C/c05/ex00/ft_iterative_factorial.c new file mode 100644 index 0000000..ed34895 --- /dev/null +++ b/C/c05/ex00/ft_iterative_factorial.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} diff --git a/C/c05/ex01/ft_recursive_factorial.c b/C/c05/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..27590d1 --- /dev/null +++ b/C/c05/ex01/ft_recursive_factorial.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/C/c05/ex03/ft_recursive_power.c b/C/c05/ex03/ft_recursive_power.c new file mode 100644 index 0000000..d2de558 --- /dev/null +++ b/C/c05/ex03/ft_recursive_power.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} diff --git a/C/c05v1/ex01/ft_recursive_factorial.c b/C/c05v1/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..27590d1 --- /dev/null +++ b/C/c05v1/ex01/ft_recursive_factorial.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/C/c05v1/ex03/ft_recursive_power.c b/C/c05v1/ex03/ft_recursive_power.c new file mode 100644 index 0000000..d2de558 --- /dev/null +++ b/C/c05v1/ex03/ft_recursive_power.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} diff --git a/C/c05v2/ex01/ft_recursive_factorial.c b/C/c05v2/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..0a52744 --- /dev/null +++ b/C/c05v2/ex01/ft_recursive_factorial.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/C/c05v2/ex03/a.out b/C/c05v2/ex03/a.out new file mode 100755 index 0000000..441d0f8 Binary files /dev/null and b/C/c05v2/ex03/a.out differ diff --git a/C/c05v2/ex03/ft_recursive_power.c b/C/c05v2/ex03/ft_recursive_power.c new file mode 100644 index 0000000..23e44e3 --- /dev/null +++ b/C/c05v2/ex03/ft_recursive_power.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} diff --git a/C/c05v3/ex01/ft_recursive_factorial.c b/C/c05v3/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..4c3f9bd --- /dev/null +++ b/C/c05v3/ex01/ft_recursive_factorial.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/C/c05v3/ex03/ft_recursive_power.c b/C/c05v3/ex03/ft_recursive_power.c new file mode 100644 index 0000000..23e44e3 --- /dev/null +++ b/C/c05v3/ex03/ft_recursive_power.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} diff --git a/C/c05v4/ex01/ft_recursive_factorial.c b/C/c05v4/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..4c3f9bd --- /dev/null +++ b/C/c05v4/ex01/ft_recursive_factorial.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/C/c05v4/ex03/ft_recursive_power.c b/C/c05v4/ex03/ft_recursive_power.c new file mode 100644 index 0000000..23e44e3 --- /dev/null +++ b/C/c05v4/ex03/ft_recursive_power.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} diff --git a/C/c05v5/ex01/ft_recursive_factorial.c b/C/c05v5/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..f4a20dc --- /dev/null +++ b/C/c05v5/ex01/ft_recursive_factorial.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/C/c05v5/ex03/ft_recursive_power.c b/C/c05v5/ex03/ft_recursive_power.c new file mode 100644 index 0000000..23e44e3 --- /dev/null +++ b/C/c05v5/ex03/ft_recursive_power.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + if (argc > 0) + print(argv[0]); +} diff --git a/C/c06/ex01/ft_print_params.c b/C/c06/ex01/ft_print_params.c new file mode 100644 index 0000000..d6da8c7 --- /dev/null +++ b/C/c06/ex01/ft_print_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + print(argv[i]); + print("\n"); + i++; + } +} diff --git a/C/c06/ex02/a.out b/C/c06/ex02/a.out new file mode 100755 index 0000000..8f40b51 Binary files /dev/null and b/C/c06/ex02/a.out differ diff --git a/C/c06/ex02/ft_rev_params.c b/C/c06/ex02/ft_rev_params.c new file mode 100644 index 0000000..f406582 --- /dev/null +++ b/C/c06/ex02/ft_rev_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = argc - 1; + while (i > 0) + { + print(argv[i]); + print("\n"); + i--; + } +} diff --git a/C/c06/ex03/ft_sort_params.c b/C/c06/ex03/ft_sort_params.c new file mode 100644 index 0000000..3247bac --- /dev/null +++ b/C/c06/ex03/ft_sort_params.c @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int ft_strcmp(char *s1, char *s2) +{ + while ((*s1 != 0 ) && (*s2 != 0) && (*s1 == *s2)) + { + s1++; + s2++; + } + return (*s1 - *s2); +} + +int ft_get_size(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +void ft_sort_int_tab(char **tab, int size) +{ + int i; + int j; + char *tempo; + + i = 0; + while (i < size) + { + j = 0; + while (j < size - 1) + { + if (ft_strcmp(tab[j], tab[j + 1]) > 0) + { + tempo = tab[j]; + tab[j] = tab[j + 1]; + tab[j + 1] = tempo; + } + j++; + } + i++; + } +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + ft_sort_int_tab(argv + 1, argc - 1); + while (i < argc) + { + ft_print(argv[i]); + ft_print("\n"); + i++; + } +} diff --git a/C/c06v1/ex00/ft_print_program_name.c b/C/c06v1/ex00/ft_print_program_name.c new file mode 100644 index 0000000..c7ad46d --- /dev/null +++ b/C/c06v1/ex00/ft_print_program_name.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_program_name.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + if (argc > 0) + print(argv[0]); +} diff --git a/C/c06v1/ex01/ft_print_params.c b/C/c06v1/ex01/ft_print_params.c new file mode 100644 index 0000000..d6da8c7 --- /dev/null +++ b/C/c06v1/ex01/ft_print_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + print(argv[i]); + print("\n"); + i++; + } +} diff --git a/C/c06v1/ex02/a.out b/C/c06v1/ex02/a.out new file mode 100755 index 0000000..8f40b51 Binary files /dev/null and b/C/c06v1/ex02/a.out differ diff --git a/C/c06v1/ex02/ft_rev_params.c b/C/c06v1/ex02/ft_rev_params.c new file mode 100644 index 0000000..f406582 --- /dev/null +++ b/C/c06v1/ex02/ft_rev_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = argc - 1; + while (i > 0) + { + print(argv[i]); + print("\n"); + i--; + } +} diff --git a/C/c06v1/ex03/ft_sort_params.c b/C/c06v1/ex03/ft_sort_params.c new file mode 100644 index 0000000..36748a6 --- /dev/null +++ b/C/c06v1/ex03/ft_sort_params.c @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int ft_strcmp(char *s1, char *s2) +{ + while ((*s1 != 0) && (*s2 != 0) && (*s1 == *s2)) + { + s1++; + s2++; + } + return (*s1 - *s2); +} + +int ft_get_size(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +void ft_sort_int_tab(char **tab, int size) +{ + int i; + int j; + char *tempo; + + i = 0; + while (i < size) + { + j = 0; + while (j < size - 1) + { + if (ft_strcmp(tab[j], tab[j + 1]) > 0) + { + tempo = tab[j]; + tab[j] = tab[j + 1]; + tab[j + 1] = tempo; + } + j++; + } + i++; + } +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + ft_sort_int_tab(argv + 1, argc - 1); + while (i < argc) + { + ft_print(argv[i]); + ft_print("\n"); + i++; + } +} diff --git a/C/c06v2.tar b/C/c06v2.tar new file mode 100644 index 0000000..506f663 Binary files /dev/null and b/C/c06v2.tar differ diff --git a/C/c06v2/ex00/ft_print_program_name.c b/C/c06v2/ex00/ft_print_program_name.c new file mode 100644 index 0000000..c7ad46d --- /dev/null +++ b/C/c06v2/ex00/ft_print_program_name.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_program_name.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + if (argc > 0) + print(argv[0]); +} diff --git a/C/c06v2/ex01/ft_print_params.c b/C/c06v2/ex01/ft_print_params.c new file mode 100644 index 0000000..d6da8c7 --- /dev/null +++ b/C/c06v2/ex01/ft_print_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + print(argv[i]); + print("\n"); + i++; + } +} diff --git a/C/c06v2/ex02/ft_rev_params.c b/C/c06v2/ex02/ft_rev_params.c new file mode 100644 index 0000000..f406582 --- /dev/null +++ b/C/c06v2/ex02/ft_rev_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = argc - 1; + while (i > 0) + { + print(argv[i]); + print("\n"); + i--; + } +} diff --git a/C/c06v2/ex03/ft_sort_params.c b/C/c06v2/ex03/ft_sort_params.c new file mode 100644 index 0000000..36748a6 --- /dev/null +++ b/C/c06v2/ex03/ft_sort_params.c @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int ft_strcmp(char *s1, char *s2) +{ + while ((*s1 != 0) && (*s2 != 0) && (*s1 == *s2)) + { + s1++; + s2++; + } + return (*s1 - *s2); +} + +int ft_get_size(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +void ft_sort_int_tab(char **tab, int size) +{ + int i; + int j; + char *tempo; + + i = 0; + while (i < size) + { + j = 0; + while (j < size - 1) + { + if (ft_strcmp(tab[j], tab[j + 1]) > 0) + { + tempo = tab[j]; + tab[j] = tab[j + 1]; + tab[j + 1] = tempo; + } + j++; + } + i++; + } +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + ft_sort_int_tab(argv + 1, argc - 1); + while (i < argc) + { + ft_print(argv[i]); + ft_print("\n"); + i++; + } +} diff --git a/C/c07/ex00/ft_strdup.c b/C/c07/ex00/ft_strdup.c new file mode 100644 index 0000000..94932b2 --- /dev/null +++ b/C/c07/ex00/ft_strdup.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +char *ft_strcpy(char *dest, char *src) +{ + int i; + + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + return (dest); +} + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *dest; + + dest = malloc(sizeof(src) * ft_strlen(src)); + ft_strcpy(dest, src); + return (dest); +} diff --git a/C/c07/ex01/ft_range.c b/C/c07/ex01/ft_range.c new file mode 100644 index 0000000..2b8df6d --- /dev/null +++ b/C/c07/ex01/ft_range.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int *ft_range(int min, int max) +{ + int i; + int *tab; + + *tab = NULL; + if (max <= min) + return (tab); + tab = malloc(sizeof(*tab) * (max - min)); + i = 0; + while (min + i < max) + { + *(tab + i) = min + i; + i++; + } + return (tab); +} diff --git a/C/c07/ex02/ft_ultimate_range.c b/C/c07/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..d681e38 --- /dev/null +++ b/C/c07/ex02/ft_ultimate_range.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + + *range = NULL; + if (max <= min) + return (0); + *range = malloc(sizeof(*range) * (max - min)); + i = 0; + while (min + i < max) + { + (*range)[i] = min + i; + i++; + } + return (max - min); +} diff --git a/C/c07/ex03/ft_strjoin.c b/C/c07/ex03/ft_strjoin.c new file mode 100644 index 0000000..9cb2db5 --- /dev/null +++ b/C/c07/ex03/ft_strjoin.c @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + char i; + + i = 0; + while (str[i] != 0) + i++; +} + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + j = 0; + i = 0; + while (dest[i] != 0) + i++; + while (src[j] != 0) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = 0; + return (dest); +} + +char *ft_strjoin(int size, char **strs, char *sep) +{ + int i; + int word_counter; + char *out; + + if (size == 0) + { + *out = malloc(sizeof(*out)); + *out = ""; + return (out); + } + i = 0; + while (i < size) + { + word_counter += ft_strlen(strs[i]); + word_counter += ft_strlen(sep); + i++; + } + out = malloc(sizeof(*out) * word_counter); + i = 0; + while (i < size) + { + ft_strcat(out, strs[i++]); + ft_strcat(out, sep); + } + return (out); +} diff --git a/C/c07/ex04/.ft_split.c.swp b/C/c07/ex04/.ft_split.c.swp new file mode 100644 index 0000000..133c7e8 Binary files /dev/null and b/C/c07/ex04/.ft_split.c.swp differ diff --git a/C/c07v1/ex00/ft_strdup.c b/C/c07v1/ex00/ft_strdup.c new file mode 100644 index 0000000..94932b2 --- /dev/null +++ b/C/c07v1/ex00/ft_strdup.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +char *ft_strcpy(char *dest, char *src) +{ + int i; + + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + return (dest); +} + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *dest; + + dest = malloc(sizeof(src) * ft_strlen(src)); + ft_strcpy(dest, src); + return (dest); +} diff --git a/C/c07v1/ex01/ft_range.c b/C/c07v1/ex01/ft_range.c new file mode 100644 index 0000000..2b8df6d --- /dev/null +++ b/C/c07v1/ex01/ft_range.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int *ft_range(int min, int max) +{ + int i; + int *tab; + + *tab = NULL; + if (max <= min) + return (tab); + tab = malloc(sizeof(*tab) * (max - min)); + i = 0; + while (min + i < max) + { + *(tab + i) = min + i; + i++; + } + return (tab); +} diff --git a/C/c07v1/ex02/ft_ultimate_range.c b/C/c07v1/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..d681e38 --- /dev/null +++ b/C/c07v1/ex02/ft_ultimate_range.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + + *range = NULL; + if (max <= min) + return (0); + *range = malloc(sizeof(*range) * (max - min)); + i = 0; + while (min + i < max) + { + (*range)[i] = min + i; + i++; + } + return (max - min); +} diff --git a/C/c07v1/ex03/ft_strjoin.c b/C/c07v1/ex03/ft_strjoin.c new file mode 100644 index 0000000..9cb2db5 --- /dev/null +++ b/C/c07v1/ex03/ft_strjoin.c @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + char i; + + i = 0; + while (str[i] != 0) + i++; +} + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + j = 0; + i = 0; + while (dest[i] != 0) + i++; + while (src[j] != 0) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = 0; + return (dest); +} + +char *ft_strjoin(int size, char **strs, char *sep) +{ + int i; + int word_counter; + char *out; + + if (size == 0) + { + *out = malloc(sizeof(*out)); + *out = ""; + return (out); + } + i = 0; + while (i < size) + { + word_counter += ft_strlen(strs[i]); + word_counter += ft_strlen(sep); + i++; + } + out = malloc(sizeof(*out) * word_counter); + i = 0; + while (i < size) + { + ft_strcat(out, strs[i++]); + ft_strcat(out, sep); + } + return (out); +} diff --git a/C/c07v1/ex04/.ft_split.c.swp b/C/c07v1/ex04/.ft_split.c.swp new file mode 100644 index 0000000..133c7e8 Binary files /dev/null and b/C/c07v1/ex04/.ft_split.c.swp differ diff --git a/C/c07v2/ex00/ft_strdup.c b/C/c07v2/ex00/ft_strdup.c new file mode 100644 index 0000000..f2c9b36 --- /dev/null +++ b/C/c07v2/ex00/ft_strdup.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +char *ft_strcpy(char *dest, char *src) +{ + int i; + + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + return (dest); +} + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *dest; + + dest = malloc(sizeof(*dest) * (ft_strlen(src) + 1)); + ft_strcpy(dest, src); + return (dest); +} diff --git a/C/c07v2/ex01/ft_range.c b/C/c07v2/ex01/ft_range.c new file mode 100644 index 0000000..c76c68f --- /dev/null +++ b/C/c07v2/ex01/ft_range.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int *ft_range(int min, int max) +{ + int i; + int *tab; + + tab = NULL; + if (max <= min) + return (tab); + tab = malloc(sizeof(*tab) * (max - min)); + i = 0; + while (min + i < max) + { + *(tab + i) = min + i; + i++; + } + return (tab); +} diff --git a/C/c07v2/ex02/ft_ultimate_range.c b/C/c07v2/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..af27483 --- /dev/null +++ b/C/c07v2/ex02/ft_ultimate_range.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + + *range = NULL; + if (max <= min) + return (0); + *range = malloc(sizeof(*range) * (max - min)); + i = 0; + while (min + i < max) + { + (*range)[i] = min + i; + i++; + } + return (max - min); +} diff --git a/C/c07v2/ex03/ft_strjoin.c b/C/c07v2/ex03/ft_strjoin.c new file mode 100644 index 0000000..6b27f0b --- /dev/null +++ b/C/c07v2/ex03/ft_strjoin.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + j = 0; + i = 0; + while (dest[i] != 0) + i++; + while (src[j] != 0) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = 0; + return (dest); +} + +char *ft_strjoin(int size, char **strs, char *sep) +{ + int i; + int word_counter; + char *out; + + if (size == 0) + { + out = malloc(sizeof(*out)); + out = ""; + return (out); + } + i = -1; + while (++i < size) + { + word_counter += ft_strlen(strs[i]); + word_counter += ft_strlen(sep); + } + out = malloc(sizeof(*out) * word_counter); + i = 0; + while (i < size) + { + ft_strcat(out, strs[i++]); + if (i < size) + ft_strcat(out, sep); + } + return (out); +} diff --git a/C/c07v2/ex05/ft_split.c b/C/c07v2/ex05/ft_split.c new file mode 100644 index 0000000..3e6bd61 --- /dev/null +++ b/C/c07v2/ex05/ft_split.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strstr(char *str, char *to_find) +{ + unsigned int i; + unsigned int j; + + i = 0; + while (str[i] != 0) + { + j = 0; + while (str[i + j] == to_find[j]) + { + if (to_find[j + 1] == 0) + return (i); + j++; + } + i++; + } + return (i); +} + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char **ft_split(char *str, char *sep) +{ + char **tab; + int i; + int j; + int k; + + i = 0; + j = 0; + tab = malloc(sizeof(*str) * ft_strlen(str)); + while (str[i] != 0 && ft_strlen(str) > i) + { + k = i; + tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1)); + while (i < k + ft_strstr(&str[k], sep)) + { + tab[j][i - k] = str[i]; + i++; + } + tab[j][i - k] = '\0'; + i = k + ft_strstr(&str[k], sep) + ft_strlen(sep); + j++; + } + tab[j] = malloc(sizeof(char)); + tab[j] = ""; + return (tab); +} diff --git a/C/c07v3/ex00/ft_strdup.c b/C/c07v3/ex00/ft_strdup.c new file mode 100644 index 0000000..f2c9b36 --- /dev/null +++ b/C/c07v3/ex00/ft_strdup.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +char *ft_strcpy(char *dest, char *src) +{ + int i; + + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + return (dest); +} + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *dest; + + dest = malloc(sizeof(*dest) * (ft_strlen(src) + 1)); + ft_strcpy(dest, src); + return (dest); +} diff --git a/C/c07v3/ex01/ft_range.c b/C/c07v3/ex01/ft_range.c new file mode 100644 index 0000000..c76c68f --- /dev/null +++ b/C/c07v3/ex01/ft_range.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int *ft_range(int min, int max) +{ + int i; + int *tab; + + tab = NULL; + if (max <= min) + return (tab); + tab = malloc(sizeof(*tab) * (max - min)); + i = 0; + while (min + i < max) + { + *(tab + i) = min + i; + i++; + } + return (tab); +} diff --git a/C/c07v3/ex02/ft_ultimate_range.c b/C/c07v3/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..af27483 --- /dev/null +++ b/C/c07v3/ex02/ft_ultimate_range.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + + *range = NULL; + if (max <= min) + return (0); + *range = malloc(sizeof(*range) * (max - min)); + i = 0; + while (min + i < max) + { + (*range)[i] = min + i; + i++; + } + return (max - min); +} diff --git a/C/c07v3/ex03/ft_strjoin.c b/C/c07v3/ex03/ft_strjoin.c new file mode 100644 index 0000000..6b27f0b --- /dev/null +++ b/C/c07v3/ex03/ft_strjoin.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + j = 0; + i = 0; + while (dest[i] != 0) + i++; + while (src[j] != 0) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = 0; + return (dest); +} + +char *ft_strjoin(int size, char **strs, char *sep) +{ + int i; + int word_counter; + char *out; + + if (size == 0) + { + out = malloc(sizeof(*out)); + out = ""; + return (out); + } + i = -1; + while (++i < size) + { + word_counter += ft_strlen(strs[i]); + word_counter += ft_strlen(sep); + } + out = malloc(sizeof(*out) * word_counter); + i = 0; + while (i < size) + { + ft_strcat(out, strs[i++]); + if (i < size) + ft_strcat(out, sep); + } + return (out); +} diff --git a/C/c07v3/ex05/ft_split.c b/C/c07v3/ex05/ft_split.c new file mode 100644 index 0000000..3e6bd61 --- /dev/null +++ b/C/c07v3/ex05/ft_split.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strstr(char *str, char *to_find) +{ + unsigned int i; + unsigned int j; + + i = 0; + while (str[i] != 0) + { + j = 0; + while (str[i + j] == to_find[j]) + { + if (to_find[j + 1] == 0) + return (i); + j++; + } + i++; + } + return (i); +} + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char **ft_split(char *str, char *sep) +{ + char **tab; + int i; + int j; + int k; + + i = 0; + j = 0; + tab = malloc(sizeof(*str) * ft_strlen(str)); + while (str[i] != 0 && ft_strlen(str) > i) + { + k = i; + tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1)); + while (i < k + ft_strstr(&str[k], sep)) + { + tab[j][i - k] = str[i]; + i++; + } + tab[j][i - k] = '\0'; + i = k + ft_strstr(&str[k], sep) + ft_strlen(sep); + j++; + } + tab[j] = malloc(sizeof(char)); + tab[j] = ""; + return (tab); +} diff --git a/C/c08/ex00/ft.h b/C/c08/ex00/ft.h new file mode 100644 index 0000000..292cd33 --- /dev/null +++ b/C/c08/ex00/ft.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +typedef t_bool int; + +# define TRUE 1 +# define FALSE 0 +# define SUCCESS 1 +# define EVEN(nbr) nbr % 2 == 0 +# define EVEN_MSG "I have an even number of arguments.\n" +# define ODD_MSG "I have an odd number of arguments.\n" + +#endif diff --git a/C/c08/ex02/ft_abs.h b/C/c08/ex02/ft_abs.h new file mode 100644 index 0000000..6719a44 --- /dev/null +++ b/C/c08/ex02/ft_abs.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_print_str(char *str) +{ + while (*str != 0) + write(1, str++, 1); + ft_putchar('\n'); +} + +void ft_print_nbr(int nbr) +{ + if (nbr > 9) + { + ft_print_nbr(nbr / 10); + ft_print_nbr(nbr % 10); + } + else + ft_putchar(nbr + 48); +} + +void ft_show_tab(struct s_stock_str *par) +{ + while (par->str[0] != 0) + { + ft_print_str(par->str); + ft_print_nbr(par->size); + ft_putchar('\n'); + ft_print_str(par->copy); + par++; + } +} diff --git a/C/c08v1/ex00/ft.h b/C/c08v1/ex00/ft.h new file mode 100644 index 0000000..292cd33 --- /dev/null +++ b/C/c08v1/ex00/ft.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +typedef int t_bool; +# define TRUE 1 +# define FALSE 0 +# define SUCCESS 0 +# define EVEN(nbr) nbr % 2 == 0 +# define EVEN_MSG "I have an even number of arguments.\n" +# define ODD_MSG "I have an odd number of arguments.\n" + +#endif diff --git a/C/c08v1/ex02/ft_abs.h b/C/c08v1/ex02/ft_abs.h new file mode 100644 index 0000000..53ba519 --- /dev/null +++ b/C/c08v1/ex02/ft_abs.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) - (Value < 0))) + +#endif diff --git a/C/c08v1/ex03/ft_point.h b/C/c08v1/ex03/ft_point.h new file mode 100644 index 0000000..bf7d5f2 --- /dev/null +++ b/C/c08v1/ex03/ft_point.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_point.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "ft_stock_str.h" + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + int i; + char *dest; + + dest = malloc(sizeof(*dest) * ft_strlen(src)); + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + dest[i] = 0; + return (dest); +} + +t_stock_str *ft_strs_to_tab(int ac, char **av) +{ + int i; + t_stock_str *tab; + + tab = malloc(sizeof(*tab) * (ac + 1)); + i = 0; + while (i < ac) + { + tab[i].size = ft_strlen(av[i]); + tab[i].str = av[i]; + tab[i].copy = ft_strdup(av[i]); + i++; + } + tab[i].str = ""; + return (tab); +} diff --git a/C/c08v1/ex05/ft_show_tab.c b/C/c08v1/ex05/ft_show_tab.c new file mode 100644 index 0000000..bad4887 --- /dev/null +++ b/C/c08v1/ex05/ft_show_tab.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_show_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "ft_stock_str.h" + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_print_str(char *str) +{ + while (*str != 0) + write(1, str++, 1); + ft_putchar('\n'); +} + +void ft_print_nbr(int nbr) +{ + if (nbr > 9) + { + ft_print_nbr(nbr / 10); + ft_print_nbr(nbr % 10); + } + else + ft_putchar(nbr + 48); +} + +void ft_show_tab(struct s_stock_str *par) +{ + while (par->str[0] != 0) + { + ft_print_str(par->str); + ft_print_nbr(par->size); + ft_putchar('\n'); + ft_print_str(par->copy); + par++; + } +} diff --git a/C/c08v2/ex00/ft.h b/C/c08v2/ex00/ft.h new file mode 100644 index 0000000..292cd33 --- /dev/null +++ b/C/c08v2/ex00/ft.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +typedef int t_bool; +# define TRUE 1 +# define FALSE 0 +# define SUCCESS 0 +# define EVEN(nbr) nbr % 2 == 0 +# define EVEN_MSG "I have an even number of arguments.\n" +# define ODD_MSG "I have an odd number of arguments.\n" + +#endif diff --git a/C/c08v2/ex02/ft_abs.h b/C/c08v2/ex02/ft_abs.h new file mode 100644 index 0000000..53ba519 --- /dev/null +++ b/C/c08v2/ex02/ft_abs.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) - (Value < 0))) + +#endif diff --git a/C/c08v2/ex03/ft_point.h b/C/c08v2/ex03/ft_point.h new file mode 100644 index 0000000..bf7d5f2 --- /dev/null +++ b/C/c08v2/ex03/ft_point.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_point.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "ft_stock_str.h" + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + int i; + char *dest; + + dest = malloc(sizeof(*dest) * ft_strlen(src)); + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + dest[i] = 0; + return (dest); +} + +t_stock_str *ft_strs_to_tab(int ac, char **av) +{ + int i; + t_stock_str *tab; + + tab = malloc(sizeof(*tab) * (ac + 1)); + i = 0; + while (i < ac) + { + tab[i].size = ft_strlen(av[i]); + tab[i].str = av[i]; + tab[i].copy = ft_strdup(av[i]); + i++; + } + tab[i].str = ""; + return (tab); +} diff --git a/C/c08v2/ex05/ft_show_tab.c b/C/c08v2/ex05/ft_show_tab.c new file mode 100644 index 0000000..bad4887 --- /dev/null +++ b/C/c08v2/ex05/ft_show_tab.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_show_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "ft_stock_str.h" + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_print_str(char *str) +{ + while (*str != 0) + write(1, str++, 1); + ft_putchar('\n'); +} + +void ft_print_nbr(int nbr) +{ + if (nbr > 9) + { + ft_print_nbr(nbr / 10); + ft_print_nbr(nbr % 10); + } + else + ft_putchar(nbr + 48); +} + +void ft_show_tab(struct s_stock_str *par) +{ + while (par->str[0] != 0) + { + ft_print_str(par->str); + ft_print_nbr(par->size); + ft_putchar('\n'); + ft_print_str(par->copy); + par++; + } +} diff --git a/C/c08v3/ex00/ft.h b/C/c08v3/ex00/ft.h new file mode 100644 index 0000000..292cd33 --- /dev/null +++ b/C/c08v3/ex00/ft.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +typedef int t_bool; +# define TRUE 1 +# define FALSE 0 +# define SUCCESS 0 +# define EVEN(nbr) nbr % 2 == 0 +# define EVEN_MSG "I have an even number of arguments.\n" +# define ODD_MSG "I have an odd number of arguments.\n" + +#endif diff --git a/C/c08v3/ex02/ft_abs.h b/C/c08v3/ex02/ft_abs.h new file mode 100644 index 0000000..53ba519 --- /dev/null +++ b/C/c08v3/ex02/ft_abs.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) - (Value < 0))) + +#endif diff --git a/C/c08v3/ex03/ft_point.h b/C/c08v3/ex03/ft_point.h new file mode 100644 index 0000000..bf7d5f2 --- /dev/null +++ b/C/c08v3/ex03/ft_point.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_point.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "ft_stock_str.h" + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + int i; + char *dest; + + dest = malloc(sizeof(*dest) * ft_strlen(src)); + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + dest[i] = 0; + return (dest); +} + +t_stock_str *ft_strs_to_tab(int ac, char **av) +{ + int i; + t_stock_str *tab; + + tab = malloc(sizeof(*tab) * (ac + 1)); + i = 0; + while (i < ac) + { + tab[i].size = ft_strlen(av[i]); + tab[i].str = av[i]; + tab[i].copy = ft_strdup(av[i]); + i++; + } + tab[i].str = ""; + return (tab); +} diff --git a/C/c08v3/ex05/ft_show_tab.c b/C/c08v3/ex05/ft_show_tab.c new file mode 100644 index 0000000..bad4887 --- /dev/null +++ b/C/c08v3/ex05/ft_show_tab.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_show_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "ft_stock_str.h" + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_print_str(char *str) +{ + while (*str != 0) + write(1, str++, 1); + ft_putchar('\n'); +} + +void ft_print_nbr(int nbr) +{ + if (nbr > 9) + { + ft_print_nbr(nbr / 10); + ft_print_nbr(nbr % 10); + } + else + ft_putchar(nbr + 48); +} + +void ft_show_tab(struct s_stock_str *par) +{ + while (par->str[0] != 0) + { + ft_print_str(par->str); + ft_print_nbr(par->size); + ft_putchar('\n'); + ft_print_str(par->copy); + par++; + } +} diff --git a/C/github.tar b/C/github.tar new file mode 100644 index 0000000..4275056 Binary files /dev/null and b/C/github.tar differ diff --git a/Correction/C01/ex00/ft_ft.c b/Correction/C01/ex00/ft_ft.c new file mode 100644 index 0000000..eab8124 --- /dev/null +++ b/Correction/C01/ex00/ft_ft.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/Correction/C01/ex01/ft_ultimate_ft.c b/Correction/C01/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..fbcf4f0 --- /dev/null +++ b/Correction/C01/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + { + write(1, str++, 1); + } +} diff --git a/Correction/C01/ex06/ft_strlen.c b/Correction/C01/ex06/ft_strlen.c new file mode 100644 index 0000000..dd3200e --- /dev/null +++ b/Correction/C01/ex06/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int a; + + a = 0; + while (*str != 0) + { + a++; + str++; + } + return (a); +} diff --git a/Correction/C01/ex07/ft_rev_int_tab.c b/Correction/C01/ex07/ft_rev_int_tab.c new file mode 100644 index 0000000..cf9c621 --- /dev/null +++ b/Correction/C01/ex07/ft_rev_int_tab.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_int_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_sort_int_tab(int *tab, int size) +{ + int i; + int j; + int tempo; + + i = 0; + while (i < size) + { + j = 0; + while (j < size - 1) + { + if (tab[j] > tab[j + 1]) + { + tempo = tab[j]; + tab[j] = tab[j + 1]; + tab[j + 1] = tempo; + } + j++; + } + i++; + } +} + +#include +int main() +{ + int tab[] = {6,-5,9,3,2,1}; + int i = 0; + + ft_sort_int_tab(tab, 6); + while (i < 6) + { + printf("%d,", tab[i]); + i++; + } +} + diff --git a/Correction/C_07ma/a.out b/Correction/C_07ma/a.out new file mode 100755 index 0000000..f946aac Binary files /dev/null and b/Correction/C_07ma/a.out differ diff --git a/Correction/C_07ma/ex00/ft_strdup.c b/Correction/C_07ma/ex00/ft_strdup.c new file mode 100644 index 0000000..f03a322 --- /dev/null +++ b/Correction/C_07ma/ex00/ft_strdup.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +char *ft_strcpy(char *dest, char *src) +{ + int i; + + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + return (dest); +} + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *dest; + + dest = malloc(sizeof(src) * ft_strlen(src)); + ft_strcpy(dest, src); + return (dest); +} + +#include + +int main(void) +{ + char str[] = "Hello World !"; + + printf("%s\n", ft_strdup(str)); +} diff --git a/Correction/C_07ma/ex01/a.out b/Correction/C_07ma/ex01/a.out new file mode 100755 index 0000000..90d70fc Binary files /dev/null and b/Correction/C_07ma/ex01/a.out differ diff --git a/Correction/C_07ma/ex01/ft_range.c b/Correction/C_07ma/ex01/ft_range.c new file mode 100644 index 0000000..edd7119 --- /dev/null +++ b/Correction/C_07ma/ex01/ft_range.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int *ft_range(int min, int max) +{ + int i; + int *tab; + + tab = NULL; + if (max <= min) + return (tab); + tab = malloc(sizeof(*tab) * (max - min)); + i = 0; + while (min + i < max) + { + *(tab + i) = min + i; + i++; + } + return (tab); +} + +#include +#include +int main(int argc, char **argv) +{ + int i; + int min; + int max; + int *tab; + + if (argc > 2) + { + i = 0; + min = atoi(argv[1]); + max = atoi(argv[2]); + tab = ft_range(min, max); + while (i < max - min) + { + printf("%d, ", *(tab + i)); + i++; + } + } +} + diff --git a/Correction/C_07ma/ex02/a.out b/Correction/C_07ma/ex02/a.out new file mode 100755 index 0000000..70187cb Binary files /dev/null and b/Correction/C_07ma/ex02/a.out differ diff --git a/Correction/C_07ma/ex02/ft_ultimate_range.c b/Correction/C_07ma/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..e46af0f --- /dev/null +++ b/Correction/C_07ma/ex02/ft_ultimate_range.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + + *range = NULL; + if (max <= min) + return (0); + *range = malloc(sizeof(*range) * (max - min)); + i = 0; + while (min + i < max) + { + (*range)[i] = min + i; + i++; + } + return (max - min); +} + +#include +int main(void) +{ + int temp1; + int *temp2; + int **tab; + + temp1 = 0; + temp2 =&temp1; + tab = &temp2; + printf("%d", ft_ultimate_range(tab, 10, 2)); + printf("\n"); + //for (int ind = 0; ind<10; ind++) + //{ + // printf("%i, ", (*tab)[ind]); + + //} + return (0); +} diff --git a/Correction/C_07ma/ex03/a.out b/Correction/C_07ma/ex03/a.out new file mode 100755 index 0000000..62dbac4 Binary files /dev/null and b/Correction/C_07ma/ex03/a.out differ diff --git a/Correction/C_07ma/ex03/ft_strjoin.c b/Correction/C_07ma/ex03/ft_strjoin.c new file mode 100644 index 0000000..70eda8d --- /dev/null +++ b/Correction/C_07ma/ex03/ft_strjoin.c @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + char i; + + i = 0; + while (str[i] != 0) + i++; +} + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + j = 0; + i = 0; + while (dest[i] != 0) + i++; + while (src[j] != 0) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = 0; + return (dest); +} + +char *ft_strjoin(int size, char **strs, char *sep) +{ + int i; + int word_counter; + char *out; + + if (size == 0) + { + out = malloc(sizeof(*out)); + out = ""; + return (out); + } + i = 0; + while (i < size) + { + word_counter += ft_strlen(strs[i]); + word_counter += ft_strlen(sep); + i++; + } + out = malloc(sizeof(*out) * word_counter); + i = 0; + while (i < size) + { + ft_strcat(out, strs[i++]); + ft_strcat(out, sep); + } + return (out); +} + +#include + +int main(int argc, char **argv) +{ + printf("%s\n", ft_strjoin(argc, argv, " ")); + return (0); +} diff --git a/Correction/C_07ma/ex04/.ft_split.c.swp b/Correction/C_07ma/ex04/.ft_split.c.swp new file mode 100644 index 0000000..133c7e8 Binary files /dev/null and b/Correction/C_07ma/ex04/.ft_split.c.swp differ diff --git a/Correction/c04corec/ex00/ft_strlen.c b/Correction/c04corec/ex00/ft_strlen.c new file mode 100644 index 0000000..f890f87 --- /dev/null +++ b/Correction/c04corec/ex00/ft_strlen.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} diff --git a/Correction/c04corec/ex02/ft_putnbr.c b/Correction/c04corec/ex02/ft_putnbr.c new file mode 100644 index 0000000..7cf66ff --- /dev/null +++ b/Correction/c04corec/ex02/ft_putnbr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr(int nbr) +{ + if (nbr == -2147483648) + { + ft_putnbr(-2); + ft_putnbr(147483648); + } + else if (nbr < 0) + { + ft_putchar('-'); + ft_putnbr(-nbr); + } + else if (nbr > 9) + { + ft_putnbr(nbr / 10); + ft_putnbr(nbr % 10); + } + else + { + ft_putchar(nbr + 48); + } +} diff --git a/Correction/c04corec/ex03/ft_atoi.c b/Correction/c04corec/ex03/ft_atoi.c new file mode 100644 index 0000000..961ebd3 --- /dev/null +++ b/Correction/c04corec/ex03/ft_atoi.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0' && str[i] <= '9') + { + nbr = (nbr * 10 + (str[i] - '0')); + i++; + } + return (nbr * sign); +} diff --git a/Correction/c04corec/ex04/a.out b/Correction/c04corec/ex04/a.out new file mode 100755 index 0000000..0f8fa16 Binary files /dev/null and b/Correction/c04corec/ex04/a.out differ diff --git a/Correction/c04corec/ex04/ft_putnbr_base.c b/Correction/c04corec/ex04/ft_putnbr_base.c new file mode 100644 index 0000000..cd55fd5 --- /dev/null +++ b/Correction/c04corec/ex04/ft_putnbr_base.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_baser(char *str) +{ + int i; + int j; + int count; + + i = -1; + while (str[++i] != 0) + { + count = 0; + j = 0; + while (str[j] != 0) + { + if (str[i] == str[j]) + count++; + j++; + } + if (count > 1) + return (0); + if (str[i] == '+') + return (0); + if (str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +void ft_put(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr_base(int nbr, char *base) +{ + int base_size; + + base_size = ft_baser(base); + if (base_size == 0) + return ; + if (nbr == -2147483648) + { + ft_putnbr_base(-2, base); + ft_putnbr_base(147483648, base); + } + else if (nbr < 0) + { + ft_put('-'); + ft_putnbr_base(-nbr, base); + } + else if (nbr > base_size - 1) + { + ft_putnbr_base(nbr / base_size, base); + ft_putnbr_base(nbr % base_size, base); + } + else + ft_put(base[nbr]); +} + +int main(void) +{ + ft_putnbr_base(56, "0123456789abcdef"); +} diff --git a/Correction/c04corec/ex05/ft_atoi_base.c b/Correction/c04corec/ex05/ft_atoi_base.c new file mode 100644 index 0000000..8959708 --- /dev/null +++ b/Correction/c04corec/ex05/ft_atoi_base.c @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 1 || str[i] == '+' || str[i] == '-') + return (0); + } + if (i == 1) + return (0); + return (i); +} + +int ft_find(char *str, char to_find) +{ + int i; + + i = 0; + while (str[i] != 0) + { + if (str[i] == to_find) + return (i); + i++; + } + return (-1); +} + +int ft_atoi_base(char *str, char *base) +{ + int base_size; + int sign; + int nbr; + int i; + + nbr = 0; + sign = 1; + base_size = ft_baser(base); + i = 0; + if (base == 0) + return (0); + while (str[i] != ' ') + i++; + while (str[i] == '+' || str[i] == '-') + if (str[i++] == '-') + sign = sign * -1; + while (ft_find(base, str[i]) != -1) + { + nbr = nbr * base_size + ft_find(base, str[i]); + str++; + } + return (nbr * sign); +} diff --git a/Correction/cc/ex00/ft_strdup.c b/Correction/cc/ex00/ft_strdup.c new file mode 100644 index 0000000..2175d51 --- /dev/null +++ b/Correction/cc/ex00/ft_strdup.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +char *ft_strcpy(char *dest, char *src) +{ + int i; + + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + return (dest); +} + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *dest; + + dest = malloc(sizeof(*dest) * (ft_strlen(src) + 1)); + ft_strcpy(dest, src); + return (dest); +} +#include +int main() +{ + ft_strdup() +} diff --git a/Correction/cc/ex01/ft_range.c b/Correction/cc/ex01/ft_range.c new file mode 100644 index 0000000..c76c68f --- /dev/null +++ b/Correction/cc/ex01/ft_range.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int *ft_range(int min, int max) +{ + int i; + int *tab; + + tab = NULL; + if (max <= min) + return (tab); + tab = malloc(sizeof(*tab) * (max - min)); + i = 0; + while (min + i < max) + { + *(tab + i) = min + i; + i++; + } + return (tab); +} diff --git a/Correction/cc/ex02/ft_ultimate_range.c b/Correction/cc/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..af27483 --- /dev/null +++ b/Correction/cc/ex02/ft_ultimate_range.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + + *range = NULL; + if (max <= min) + return (0); + *range = malloc(sizeof(*range) * (max - min)); + i = 0; + while (min + i < max) + { + (*range)[i] = min + i; + i++; + } + return (max - min); +} diff --git a/Correction/cc/ex03/ft_strjoin.c b/Correction/cc/ex03/ft_strjoin.c new file mode 100644 index 0000000..6b27f0b --- /dev/null +++ b/Correction/cc/ex03/ft_strjoin.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + j = 0; + i = 0; + while (dest[i] != 0) + i++; + while (src[j] != 0) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = 0; + return (dest); +} + +char *ft_strjoin(int size, char **strs, char *sep) +{ + int i; + int word_counter; + char *out; + + if (size == 0) + { + out = malloc(sizeof(*out)); + out = ""; + return (out); + } + i = -1; + while (++i < size) + { + word_counter += ft_strlen(strs[i]); + word_counter += ft_strlen(sep); + } + out = malloc(sizeof(*out) * word_counter); + i = 0; + while (i < size) + { + ft_strcat(out, strs[i++]); + if (i < size) + ft_strcat(out, sep); + } + return (out); +} diff --git a/Correction/cc/ex05/ft_split.c b/Correction/cc/ex05/ft_split.c new file mode 100644 index 0000000..3e6bd61 --- /dev/null +++ b/Correction/cc/ex05/ft_split.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strstr(char *str, char *to_find) +{ + unsigned int i; + unsigned int j; + + i = 0; + while (str[i] != 0) + { + j = 0; + while (str[i + j] == to_find[j]) + { + if (to_find[j + 1] == 0) + return (i); + j++; + } + i++; + } + return (i); +} + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char **ft_split(char *str, char *sep) +{ + char **tab; + int i; + int j; + int k; + + i = 0; + j = 0; + tab = malloc(sizeof(*str) * ft_strlen(str)); + while (str[i] != 0 && ft_strlen(str) > i) + { + k = i; + tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1)); + while (i < k + ft_strstr(&str[k], sep)) + { + tab[j][i - k] = str[i]; + i++; + } + tab[j][i - k] = '\0'; + i = k + ft_strstr(&str[k], sep) + ft_strlen(sep); + j++; + } + tab[j] = malloc(sizeof(char)); + tab[j] = ""; + return (tab); +} diff --git a/Correction/cchauvetc06_1/a.out b/Correction/cchauvetc06_1/a.out new file mode 100755 index 0000000..8930a3e Binary files /dev/null and b/Correction/cchauvetc06_1/a.out differ diff --git a/Correction/cchauvetc06_1/ex00/a.out b/Correction/cchauvetc06_1/ex00/a.out new file mode 100755 index 0000000..430d2b8 Binary files /dev/null and b/Correction/cchauvetc06_1/ex00/a.out differ diff --git a/Correction/cchauvetc06_1/ex00/ft_print_program_name.c b/Correction/cchauvetc06_1/ex00/ft_print_program_name.c new file mode 100644 index 0000000..1cf5fb2 --- /dev/null +++ b/Correction/cchauvetc06_1/ex00/ft_print_program_name.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_program_name.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mlauro +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/25 13:22:56 by mlauro #+# #+# */ +/* Updated: 2022/08/01 13:04:03 by mlauro ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int main(int argc, char **argv) +{ + int i; + + i = 0; + if (argc >= 0) + { + while (argv[0][i]) + write(1, &argv[0][i++], 1); + } + write(1, "\n", 1); +} diff --git a/Correction/cchauvetc06_1/ex01/ft_print_params.c b/Correction/cchauvetc06_1/ex01/ft_print_params.c new file mode 100644 index 0000000..19b6b97 --- /dev/null +++ b/Correction/cchauvetc06_1/ex01/ft_print_params.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mlauro +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/25 14:20:22 by mlauro #+# #+# */ +/* Updated: 2022/07/25 14:23:49 by mlauro ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int main(int argc, char **argv) +{ + int i; + int j; + + i = 1; + j = 0; + while (i < argc) + { + j = 0; + while (argv[i][j]) + { + write(1, &argv[i][j], 1); + j++; + } + write(1, "\n", 1); + i++; + } + return (0); +} diff --git a/Correction/cchauvetc06_1/ex02/ft_rev_params.c b/Correction/cchauvetc06_1/ex02/ft_rev_params.c new file mode 100644 index 0000000..4ee12fb --- /dev/null +++ b/Correction/cchauvetc06_1/ex02/ft_rev_params.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mlauro +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/25 14:26:07 by mlauro #+# #+# */ +/* Updated: 2022/08/01 14:22:25 by mlauro ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int main(int argc, char **argv) +{ + int i; + int j; + + i = argc; + while (i > 1) + { + j = 0; + while (argv[i - 1][j]) + { + write(1, &argv[i - 1][j], 1); + j++; + } + write(1, "\n", 1); + i--; + } + return (0); +} diff --git a/Correction/cchauvetc06_1/ex03/ft_sort_params.c b/Correction/cchauvetc06_1/ex03/ft_sort_params.c new file mode 100644 index 0000000..10fb5f4 --- /dev/null +++ b/Correction/cchauvetc06_1/ex03/ft_sort_params.c @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mlauro +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/25 14:29:51 by mlauro #+# #+# */ +/* Updated: 2022/07/25 17:32:53 by mlauro ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_strcmp(char *s1, char *s2) +{ + int i; + + i = 0; + while (s1[i] != '\0' && s2[i] != '\0') + { + if (s1[i] != s2[i]) + { + return (s1[i] - s2[i]); + } + i++; + } + return (s1[i] - s2[i]); +} + +void print_string(char *s) +{ + int i; + + i = 0; + while (s[i]) + write(1, &s[i++], 1); + write(1, "\n", 1); +} + +void ft_sort_argv(int argc, char **argv) +{ + char *tmp; + int i; + int j; + + i = 1; + while (i < argc - 1) + { + j = 0; + while (j < argc - 1) + { + if (ft_strcmp(argv[j], argv[j + 1]) > 0) + { + tmp = argv[j]; + argv[j] = argv[j + 1]; + argv[j + 1] = tmp; + } + j++; + } + i++; + } +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + ft_sort_argv(argc, argv); + while (i < argc) + { + print_string(argv[i]); + i++; + } +} diff --git a/Correction/corC05ma/ex00/a.out b/Correction/corC05ma/ex00/a.out new file mode 100755 index 0000000..3b6cc16 Binary files /dev/null and b/Correction/corC05ma/ex00/a.out differ diff --git a/Correction/corC05ma/ex00/ft_iterative_factorial.c b/Correction/corC05ma/ex00/ft_iterative_factorial.c new file mode 100644 index 0000000..4b2de1a --- /dev/null +++ b/Correction/corC05ma/ex00/ft_iterative_factorial.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} + +#include +#include + +int main(int argc, char *argv[]) +{ + if (argc > 1) + printf("%d", ft_iterative_factorial(atoi(argv[1]))); +} diff --git a/Correction/corC05ma/ex01/ft_recursive_factorial.c b/Correction/corC05ma/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..0a52744 --- /dev/null +++ b/Correction/corC05ma/ex01/ft_recursive_factorial.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/Correction/corC05ma/ex03/ft_recursive_power.c b/Correction/corC05ma/ex03/ft_recursive_power.c new file mode 100644 index 0000000..23e44e3 --- /dev/null +++ b/Correction/corC05ma/ex03/ft_recursive_power.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/Correction/correc_c01v/ex01/ft_ultimate_ft.c b/Correction/correc_c01v/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..fbcf4f0 --- /dev/null +++ b/Correction/correc_c01v/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + { + write(1, str++, 1); + } +} diff --git a/Correction/correc_c01v/ex06/ft_strlen.c b/Correction/correc_c01v/ex06/ft_strlen.c new file mode 100644 index 0000000..dd3200e --- /dev/null +++ b/Correction/correc_c01v/ex06/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int a; + + a = 0; + while (*str != 0) + { + a++; + str++; + } + return (a); +} diff --git a/Correction/correc_c01v/ex07/ft_rev_int_tab.c b/Correction/correc_c01v/ex07/ft_rev_int_tab.c new file mode 100644 index 0000000..cf9c621 --- /dev/null +++ b/Correction/correc_c01v/ex07/ft_rev_int_tab.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_int_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_sort_int_tab(int *tab, int size) +{ + int i; + int j; + int tempo; + + i = 0; + while (i < size) + { + j = 0; + while (j < size - 1) + { + if (tab[j] > tab[j + 1]) + { + tempo = tab[j]; + tab[j] = tab[j + 1]; + tab[j + 1] = tempo; + } + j++; + } + i++; + } +} +/* +#include +int main() +{ + int tab[] = {6,5,4,3,2,1}; + int i = 0; + + ft_sort_int_tab(tab, 6); + while (i < 6) + { + printf("%d,", tab[i]); + i++; + } +} +*/ diff --git a/Correction/correctionc07/ex00/a.out b/Correction/correctionc07/ex00/a.out new file mode 100755 index 0000000..40a8363 Binary files /dev/null and b/Correction/correctionc07/ex00/a.out differ diff --git a/Correction/correctionc07/ex00/ft_strdup.c b/Correction/correctionc07/ex00/ft_strdup.c new file mode 100644 index 0000000..ba434a1 --- /dev/null +++ b/Correction/correctionc07/ex00/ft_strdup.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +char *ft_strcpy(char *dest, char *src) +{ + int i; + + i = 0; + while (src[i] != 0) + { + dest[i] = src[i]; + i++; + } + return (dest); +} + +unsigned int ft_strlen(char *str) +{ + unsigned int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *dest; + + dest = malloc(sizeof(*dest) * ft_strlen(src)); + ft_strcpy(dest, src); + return (dest); +} + +#include +int main(void) +{ + char str[] = "Bonjour"; + printf("%c", ft_strdup(str)[8]); +} diff --git a/Correction/correctionc07/ex01/a.out b/Correction/correctionc07/ex01/a.out new file mode 100755 index 0000000..a11cabd Binary files /dev/null and b/Correction/correctionc07/ex01/a.out differ diff --git a/Correction/correctionc07/ex01/ft_range.c b/Correction/correctionc07/ex01/ft_range.c new file mode 100644 index 0000000..3f47043 --- /dev/null +++ b/Correction/correctionc07/ex01/ft_range.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int *ft_range(int min, int max) +{ + int i; + int *tab; + + tab = NULL; + if (max <= min) + return (tab); + tab = malloc(sizeof(*tab) * (max - min + 1)); + i = 0; + while (min + i < max) + { + *(tab + i) = min + i; + i++; + } + return (tab); +} + +#include +int main(void) +{ + int i; + i = 0; + while (i < 6) + { + printf("%d", ft_range(4, 10)[i]); + i++; + } +} diff --git a/Correction/correctionc07/ex02/a.out b/Correction/correctionc07/ex02/a.out new file mode 100755 index 0000000..a467be0 Binary files /dev/null and b/Correction/correctionc07/ex02/a.out differ diff --git a/Correction/correctionc07/ex02/ft_ultimate_range.c b/Correction/correctionc07/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..7961fed --- /dev/null +++ b/Correction/correctionc07/ex02/ft_ultimate_range.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + + *range = NULL; + if (max <= min) + return (0); + *range = malloc(sizeof(*range) * (max - min + 1)); + i = 0; + while (min + i < max) + { + (*range)[i] = min + i; + i++; + } + return (max - min); +} + +#include +int main(void) +{ + int temp1; + int *temp2; + int **tab; + + temp1 = 0; + temp2 =&temp1; + tab = &temp2; + printf("%d", ft_ultimate_range(tab, 11, 10)); + printf("\n"); + for (int ind = 0; ind<10; ind++ ) + { + printf("%i, ", (*tab)[ind]); + + } + return (0); +} diff --git a/Correction/correctionc07/ex03/a.out b/Correction/correctionc07/ex03/a.out new file mode 100755 index 0000000..dfb4821 Binary files /dev/null and b/Correction/correctionc07/ex03/a.out differ diff --git a/Correction/correctionc07/ex03/ft_strjoin.c b/Correction/correctionc07/ex03/ft_strjoin.c new file mode 100644 index 0000000..9d10df1 --- /dev/null +++ b/Correction/correctionc07/ex03/ft_strjoin.c @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + j = 0; + i = 0; + while (dest[i] != 0) + i++; + while (src[j] != 0) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = 0; + return (dest); +} + +char *ft_strjoin(int size, char **strs, char *sep) +{ + int i; + int word_counter; + char *out; + + if (size == 0) + { + out = malloc(sizeof(*out)); + out = ""; + return (out); + } + i = -1; + while (++i < size) + { + word_counter += ft_strlen(strs[i]); + word_counter += ft_strlen(sep); + } + out = malloc(sizeof(*out) * word_counter); + i = 0; + while (i < size) + { + ft_strcat(out, strs[i++]); + if (i < size) + ft_strcat(out, sep); + } + return (out); +} + +#include +int main(int argc, char **argv) +{ + printf("%s", ft_strjoin(argc, argv, " ")); +} diff --git a/Correction/correctionc07/ex04/.ft_split.c.swp b/Correction/correctionc07/ex04/.ft_split.c.swp new file mode 100644 index 0000000..133c7e8 Binary files /dev/null and b/Correction/correctionc07/ex04/.ft_split.c.swp differ diff --git a/Correction/correctionc07/ex05/ft_split.c b/Correction/correctionc07/ex05/ft_split.c new file mode 100644 index 0000000..3e6bd61 --- /dev/null +++ b/Correction/correctionc07/ex05/ft_split.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strstr(char *str, char *to_find) +{ + unsigned int i; + unsigned int j; + + i = 0; + while (str[i] != 0) + { + j = 0; + while (str[i + j] == to_find[j]) + { + if (to_find[j + 1] == 0) + return (i); + j++; + } + i++; + } + return (i); +} + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +char **ft_split(char *str, char *sep) +{ + char **tab; + int i; + int j; + int k; + + i = 0; + j = 0; + tab = malloc(sizeof(*str) * ft_strlen(str)); + while (str[i] != 0 && ft_strlen(str) > i) + { + k = i; + tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1)); + while (i < k + ft_strstr(&str[k], sep)) + { + tab[j][i - k] = str[i]; + i++; + } + tab[j][i - k] = '\0'; + i = k + ft_strstr(&str[k], sep) + ft_strlen(sep); + j++; + } + tab[j] = malloc(sizeof(char)); + tab[j] = ""; + return (tab); +} diff --git a/Correction/d/a.out b/Correction/d/a.out new file mode 100755 index 0000000..cdfbc36 Binary files /dev/null and b/Correction/d/a.out differ diff --git a/Correction/d/ex00/ft_iterative_factorial.c b/Correction/d/ex00/ft_iterative_factorial.c new file mode 100644 index 0000000..e1c74e2 --- /dev/null +++ b/Correction/d/ex00/ft_iterative_factorial.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 13:05:38 by lflandri #+# #+# */ +/* Updated: 2022/07/20 13:05:39 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_iterative_factorial(int nb) +{ + int n; + + if (nb < 0) + return (0); + n = 1; + while (nb) + n = n * nb--; + return (n); +} diff --git a/Correction/d/ex01/ft_recursive_factorial.c b/Correction/d/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..166617f --- /dev/null +++ b/Correction/d/ex01/ft_recursive_factorial.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 13:17:09 by lflandri #+# #+# */ +/* Updated: 2022/07/20 13:17:10 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_factorial(int nb) +{ + if (nb < 0) + return (0); + else if (nb > 1) + return (nb * ft_recursive_factorial(nb - 1)); + return (1); +} diff --git a/Correction/d/ex02/ft_iterative_power.c b/Correction/d/ex02/ft_iterative_power.c new file mode 100644 index 0000000..aa61dd9 --- /dev/null +++ b/Correction/d/ex02/ft_iterative_power.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 13:25:45 by lflandri #+# #+# */ +/* Updated: 2022/07/20 13:25:46 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_iterative_power(int nb, int power) +{ + int stock; + + stock = 1; + if (power < 0) + return (0); + while (power--) + stock = stock * nb; + return (stock); +} diff --git a/Correction/d/ex03/ft_recursive_power.c b/Correction/d/ex03/ft_recursive_power.c new file mode 100644 index 0000000..345af02 --- /dev/null +++ b/Correction/d/ex03/ft_recursive_power.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 16:44:43 by lflandri #+# #+# */ +/* Updated: 2022/07/20 16:44:44 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_power(int nb, int p) +{ + if (p > 0) + return (nb * ft_recursive_power(nb, p - 1)); + if (p == 0) + return (1); + return (0); +} diff --git a/Correction/d/ex04/ft_fibonacci.c b/Correction/d/ex04/ft_fibonacci.c new file mode 100644 index 0000000..8eb2879 --- /dev/null +++ b/Correction/d/ex04/ft_fibonacci.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_fibonacci.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 17:16:27 by lflandri #+# #+# */ +/* Updated: 2022/07/20 17:16:27 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_fibonacci(int index) +{ + if (!(index)) + return (0); + if (index < 0) + return (-1); + if (index == 1) + return (1); + return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2)); +} diff --git a/Correction/d/ex05/ft_sqrt.c b/Correction/d/ex05/ft_sqrt.c new file mode 100644 index 0000000..51b6397 --- /dev/null +++ b/Correction/d/ex05/ft_sqrt.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sqrt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 19:03:04 by lflandri #+# #+# */ +/* Updated: 2022/07/24 15:50:32 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_sqrt_bis(long int nb, int max, int min) +{ + long int middle; + + middle = (max - min) / 2 + min; + if (middle * middle == nb) + return (middle); + else if (min + 1 == max) + return (0); + else if (middle * middle > nb) + return (ft_sqrt_bis(nb, middle, min)); + else + return (ft_sqrt_bis(nb, max, middle)); +} + +int ft_sqrt(int nb) +{ + if (nb < 0) + return (0); + return (ft_sqrt_bis(nb, nb, 0)); +} + +#include +#include +int main(int ac, char **av) +{ + if (ac != 2) + return (0); + printf("%d", ft_sqrt(atoi(av[1]))); +} diff --git a/Correction/d/ex06/ft_is_prime.c b/Correction/d/ex06/ft_is_prime.c new file mode 100644 index 0000000..b1498e4 --- /dev/null +++ b/Correction/d/ex06/ft_is_prime.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_prime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/21 10:46:05 by lflandri #+# #+# */ +/* Updated: 2022/07/21 10:46:06 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_prime(int nb) +{ + int ind; + + if (nb <= 1) + return (0); + ind = 2; + while (ind < nb / 2) + { + if (!(nb % ind)) + return (0); + ind++; + } + return (1); +} diff --git a/Correction/d/ex07/ft_find_next_prime.c b/Correction/d/ex07/ft_find_next_prime.c new file mode 100644 index 0000000..d1e93ef --- /dev/null +++ b/Correction/d/ex07/ft_find_next_prime.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_next_prime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/21 10:46:05 by lflandri #+# #+# */ +/* Updated: 2022/07/21 14:42:31 by lflandri ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_prime(int nb) +{ + int ind; + + if (nb <= 1) + return (0); + ind = 2; + while (ind < nb / 2) + { + if (!(nb % ind)) + return (0); + ind++; + } + return (1); +} + +int ft_find_next_prime(int nb) +{ + if (nb <= 2) + return (2); + if (!(nb % 2)) + nb++; + while (1) + { + if (ft_is_prime(nb)) + return (nb); + nb += 2; + } +} diff --git a/Correction/d/ex08/ft_ten_queens_puzzle.c b/Correction/d/ex08/ft_ten_queens_puzzle.c new file mode 100644 index 0000000..929a756 --- /dev/null +++ b/Correction/d/ex08/ft_ten_queens_puzzle.c @@ -0,0 +1,102 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ten_queens_puzzle.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lflandri +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/21 14:43:07 by lflandri #+# #+# */ +/* Updated: 2022/07/24 16:26:44 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_recursive(int tab[10][10], char *solution, int rang); + +int insert_d(int tab[10][10], char *solution, int rang, int ind) +{ + int hauteur; + int rang_tempo; + + rang_tempo = rang + 1; + hauteur = 1; + tab[rang][ind] = 2; + while (rang_tempo != 10) + { + tab[rang_tempo][ind] = 1; + if (ind - hauteur >= 0) + tab[rang_tempo][ind - hauteur] = 1; + if (ind + hauteur < 10) + tab[rang_tempo][ind + hauteur] = 1; + rang_tempo++; + hauteur++; + } + return (ft_recursive(tab, solution, rang + 1)); +} + +int cptab(int tab[10][10], char *solution, int rang, int ind) +{ + int x; + int y; + int tab_copy[10][10]; + + x = 0; + while (x != 10) + { + y = -1; + while (++y != 10) + tab_copy[x][y] = tab[x][y]; + x++; + } + return (insert_d(tab_copy, solution, rang, ind)); +} + +int ft_recursive(int tab[10][10], char *solution, int rang) +{ + int ind; + int count; + + count = 0; + ind = 0; + if (rang == 10) + { + write(1, solution, 11); + count++; + } + else + { + while (ind != 10) + { + if (!(tab[rang][ind])) + { + *(solution + rang) = ind + 48; + count += cptab(tab, solution, rang, ind); + } + ind++; + } + } + return (count); +} + +int ft_ten_queens_puzzle(void) +{ + int tab[10][10]; + char solution[11]; + int x; + int y; + + x = 0; + while (x != 10) + { + y = -1; + while (++y != 10) + tab[x][y] = 0; + x++; + } + solution[10] = '\n'; + return (ft_recursive(tab, solution, 0)); +} + +int main() + diff --git a/Correction/dfdgdf/a.out b/Correction/dfdgdf/a.out new file mode 100755 index 0000000..0a7f7f8 Binary files /dev/null and b/Correction/dfdgdf/a.out differ diff --git a/Correction/dfdgdf/ex00/ft_strcmp.c b/Correction/dfdgdf/ex00/ft_strcmp.c new file mode 100644 index 0000000..6c07e9a --- /dev/null +++ b/Correction/dfdgdf/ex00/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jmendez +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 13:44:45 by jmendez #+# #+# */ +/* Updated: 2022/07/20 14:29:30 by jmendez ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_strcmp(char *s1, char *s2) +{ + int i; + + i = 0; + while (s1[i] == s2[i] && (s1[i] && s2[i])) + i ++; + return (s1[i] - s2[i]); +} diff --git a/Correction/dfdgdf/ex01/ft_strncmp.c b/Correction/dfdgdf/ex01/ft_strncmp.c new file mode 100644 index 0000000..1edf526 --- /dev/null +++ b/Correction/dfdgdf/ex01/ft_strncmp.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jmendez +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 14:58:04 by jmendez #+# #+# */ +/* Updated: 2022/07/20 15:00:50 by jmendez ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + unsigned int i; + + i = 0; + while (i < n) + { + if (s1[i] != s2[i] || s1[i] == '\0' || s2[i] == '\0') + { + return (s1[i] - s2[i]); + } + i++; + } + return (0); +} diff --git a/Correction/dfdgdf/ex02/ft_strcat.c b/Correction/dfdgdf/ex02/ft_strcat.c new file mode 100644 index 0000000..bc75fc0 --- /dev/null +++ b/Correction/dfdgdf/ex02/ft_strcat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jmendez +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 20:57:39 by jmendez #+# #+# */ +/* Updated: 2022/07/20 22:44:31 by jmendez ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcat(char *dest, char *src) +{ + int i; + int j; + + i = 0; + j = 0; + while (dest[i] != '\0') + i++; + while (src[j] != '\0') + { + dest[i] = src[j]; + i++; + j++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/Correction/dfdgdf/ex03/ft_strncat.c b/Correction/dfdgdf/ex03/ft_strncat.c new file mode 100644 index 0000000..7bc34af --- /dev/null +++ b/Correction/dfdgdf/ex03/ft_strncat.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jmendez +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 22:47:28 by jmendez #+# #+# */ +/* Updated: 2022/07/25 16:53:34 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncat(char *dest, char *src, unsigned int nb) +{ + int i; + unsigned int j; + + i = 0; + j = 0; + while (dest[i] != '\0') + i++; + while (j < nb) + { + dest[i] = src[j]; + i++; + j++; + } + return (dest); +} + +#include +#include + +int main() +{ + char a[] = "sss"; + char b[] = "aaa"; + char c[] = "aaa"; + + printf("%s", strncat(b, a, 5)); + printf("\n%s", ft_strncat(c, a, 5)); + +} diff --git a/Correction/dfdgdf/ex04/ft_strstr.c b/Correction/dfdgdf/ex04/ft_strstr.c new file mode 100644 index 0000000..54a295d --- /dev/null +++ b/Correction/dfdgdf/ex04/ft_strstr.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jmendez +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/21 12:35:36 by jmendez #+# #+# */ +/* Updated: 2022/07/25 16:56:29 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strstr(char *str, char *to_find) +{ + int i; + int j; + + i = 0; + j = 0; + if (to_find[j] == '\0') + return (str); + while (str[i] != '\0') + { + if (str[i] == to_find[j]) + { + while (str[i] == to_find[j]) + { + i++; + j++; + if (to_find[j] == '\0') + return (&str[i - j]); + } + i = i - j; + } + j = 0; + i++; + } + return (NULL); +} + +#include +#include + + +int main (void) { + char haystack1[20] = "TutorialsPoint"; + char needle1[10] = "Pint"; + char *ret1; + + ret1 = strstr(haystack1, needle1); + + printf("The substring is: %s\n", ret1); + + + printf("\n"); + + + char haystack2[20] = "TutorialsPoint"; + char needle2[10] = "Pint"; + char *ret2; + + ret2 = ft_strstr(haystack2, needle2); + + printf("The substring is: %s\n", ret2); + + return(0); +} + diff --git a/Correction/dfdgdf/ex05/ft_strlcat.c b/Correction/dfdgdf/ex05/ft_strlcat.c new file mode 100644 index 0000000..993d8fd --- /dev/null +++ b/Correction/dfdgdf/ex05/ft_strlcat.c @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jmendez +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/21 17:13:43 by jmendez #+# #+# */ +/* Updated: 2022/07/25 17:00:32 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int howmuch; + + howmuch = 0; + while (*str++) + howmuch++; + return (howmuch); +} + +unsigned int ft_strlcpy(char *dest, char *src, unsigned int size) +{ + unsigned int i; + + i = -1; + while (++i < size - 1 && src[i]) + dest[i] = src[i]; + dest[i + 1] = '\0'; + return (i); +} + +unsigned int ft_strlcat(char *dest, char *src, unsigned int size) +{ + unsigned int length; + + length = ft_strlen(dest); + if (length >= size) + length = size; + if (length == size) + return (length + ft_strlen(src)); + return (length + ft_strlcpy(dest + length, src, size - length)); +} + +#include +int main() +{ + char src[] = "hello"; + char dest2[10] = "fjff"; + int j; + + j = ft_strlcat(dest2, src, 7); + + printf("%d %s\n", j, dest2); +} + diff --git a/Correction/gpouzet/ex00/ft_ft.c b/Correction/gpouzet/ex00/ft_ft.c new file mode 100644 index 0000000..eab8124 --- /dev/null +++ b/Correction/gpouzet/ex00/ft_ft.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/Correction/gpouzet/ex01/ft_ultimate_ft.c b/Correction/gpouzet/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..fbcf4f0 --- /dev/null +++ b/Correction/gpouzet/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putstr(char *str) +{ + while (*str != 0) + { + write(1, str++, 1); + } +} diff --git a/Correction/gpouzet/ex06/ft_strlen.c b/Correction/gpouzet/ex06/ft_strlen.c new file mode 100644 index 0000000..dd3200e --- /dev/null +++ b/Correction/gpouzet/ex06/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_strlen(char *str) +{ + int a; + + a = 0; + while (*str != 0) + { + a++; + str++; + } + return (a); +} diff --git a/Correction/gpouzet/ex07/ft_rev_int_tab.c b/Correction/gpouzet/ex07/ft_rev_int_tab.c new file mode 100644 index 0000000..cf9c621 --- /dev/null +++ b/Correction/gpouzet/ex07/ft_rev_int_tab.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_int_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main() +{ + char src1[] = "dddd"; + char dest1[8] = "dddid"; + int result1; + + result1 = strcmp(dest1, src1); + printf("%d", result1); + + + printf("\n"); + + + char src2[] = "dddd"; + char dest2[8] = "dddid"; + int result2; + + result2 = ft_strcmp(dest2, src2); + printf("%d", result2); + return 0; +} + diff --git a/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex01/a.out b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex01/a.out new file mode 100755 index 0000000..93fd27f Binary files /dev/null and b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex01/a.out differ diff --git a/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex01/ft_strncmp.c b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex01/ft_strncmp.c new file mode 100644 index 0000000..0ccb20f --- /dev/null +++ b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex01/ft_strncmp.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main() +{ + char src1[] = "dddd"; + char dest1[8] = "ddde"; + int result1; + + result1 = strncmp(dest1, src1, 5); + printf("%d", result1); + + + printf("\n"); + + + char src2[] = "dddd"; + char dest2[8] = "ddde"; + int result2; + + result2 = ft_strncmp(dest2, src2, 5); + printf("%d", result2); + return 0; +} diff --git a/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex02/a.out b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex02/a.out new file mode 100755 index 0000000..a2742ef Binary files /dev/null and b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex02/a.out differ diff --git a/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex02/ft_strcat.c b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex02/ft_strcat.c new file mode 100644 index 0000000..4b8e05d --- /dev/null +++ b/Correction/intra-uuid-3a0b91e4-1f01-4cc3-9341-c60452b16375-4258902-cchauvet/ex02/ft_strcat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} diff --git a/Correction/leolmeilleurvoisin/ex01/ft_recursive_factorial.c b/Correction/leolmeilleurvoisin/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..27590d1 --- /dev/null +++ b/Correction/leolmeilleurvoisin/ex01/ft_recursive_factorial.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} diff --git a/Correction/leolmeilleurvoisin/ex03/ft_recursive_power.c b/Correction/leolmeilleurvoisin/ex03/ft_recursive_power.c new file mode 100644 index 0000000..d2de558 --- /dev/null +++ b/Correction/leolmeilleurvoisin/ex03/ft_recursive_power.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int main(void) +{ + printf("%d", ft_is_prime(1)); +} diff --git a/Correction/leolmeilleurvoisin/ex07/ft_find_next_prime.c b/Correction/leolmeilleurvoisin/ex07/ft_find_next_prime.c new file mode 100644 index 0000000..600fdf5 --- /dev/null +++ b/Correction/leolmeilleurvoisin/ex07/ft_find_next_prime.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_next_prime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +char *ft_strcpy(char *dest, char *src) +{ + while (*src != '\0') + { + *dest = *src; + src++; + dest++; + } + *dest = '\0'; + return (dest); +} + +int main(void) +{ + char dest[1]; + char dest1[1]; + char src[] = "abcde"; + + ft_strcpy(dest, src); + printf("%s \n\n", dest); + strcpy(dest1, src); + printf("%s \n\n", dest1); + + return (0); +} diff --git a/Correction/lev/ex01/ft_strncpy.c b/Correction/lev/ex01/ft_strncpy.c new file mode 100644 index 0000000..992efc1 --- /dev/null +++ b/Correction/lev/ex01/ft_strncpy.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} diff --git a/Correction/lev/ex03/ft_str_is_numeric.c b/Correction/lev/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..daeba52 --- /dev/null +++ b/Correction/lev/ex03/ft_str_is_numeric.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} diff --git a/Correction/lev/ex04/ft_str_is_lowercase.c b/Correction/lev/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..cc4e5aa --- /dev/null +++ b/Correction/lev/ex04/ft_str_is_lowercase.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int main() +{ + char str[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un"; + printf("%s\n", str); + printf("%s", ft_strcapitalize(str)); +} +*/ diff --git a/Correction/levv/ex00/ft_strcpy.c b/Correction/levv/ex00/ft_strcpy.c new file mode 100644 index 0000000..5985d7c --- /dev/null +++ b/Correction/levv/ex00/ft_strcpy.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} diff --git a/Correction/levv/ex03/ft_str_is_numeric.c b/Correction/levv/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..daeba52 --- /dev/null +++ b/Correction/levv/ex03/ft_str_is_numeric.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} diff --git a/Correction/levv/ex04/ft_str_is_lowercase.c b/Correction/levv/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..cc4e5aa --- /dev/null +++ b/Correction/levv/ex04/ft_str_is_lowercase.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +int main(void) +{ + char str[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un"; + printf("%s",ft_strcapitalize(str)); +} diff --git a/Correction/levv/ex10/a.out b/Correction/levv/ex10/a.out new file mode 100755 index 0000000..a449d3f Binary files /dev/null and b/Correction/levv/ex10/a.out differ diff --git a/Correction/levv/ex10/ft_strlcpy.c b/Correction/levv/ex10/ft_strlcpy.c new file mode 100644 index 0000000..d001e4a --- /dev/null +++ b/Correction/levv/ex10/ft_strlcpy.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main(void) +{ + char src[42] = "jetest"; + char dest[42]; + printf("%d\n", ft_strlcpy(dest, src, 4)); + printf("%ld", strlcpy(dest, src, 4)); +} diff --git a/Correction/matyss/ex00/ft_strcpy.c b/Correction/matyss/ex00/ft_strcpy.c new file mode 100644 index 0000000..5985d7c --- /dev/null +++ b/Correction/matyss/ex00/ft_strcpy.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = *str))) + { + return (0); + } + str++; + } + return (1); +} diff --git a/Correction/matyss/ex03/ft_str_is_numeric.c b/Correction/matyss/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..daeba52 --- /dev/null +++ b/Correction/matyss/ex03/ft_str_is_numeric.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0') && (*str <= '9'))) + return (0); + str++; + } + return (1); +} diff --git a/Correction/matyss/ex04/ft_str_is_lowercase.c b/Correction/matyss/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..cc4e5aa --- /dev/null +++ b/Correction/matyss/ex04/ft_str_is_lowercase.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + { + nbr_out = nbr_out * nb; + nb--; + } + return (nbr_out); +} + +#include +#include + +int main(int argc, char *argv[]) +{ + if (argc > 1) + printf("%d", ft_iterative_factorial(atoi(argv[1]))); +} diff --git a/Correction/sam/ex01/a.out b/Correction/sam/ex01/a.out new file mode 100755 index 0000000..c813d99 Binary files /dev/null and b/Correction/sam/ex01/a.out differ diff --git a/Correction/sam/ex01/ft_recursive_factorial.c b/Correction/sam/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..7dee8e6 --- /dev/null +++ b/Correction/sam/ex01/ft_recursive_factorial.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main(int argc, char *argv[]) +{ + if (argc > 1) + printf("%d", ft_recursive_factorial(atoi(argv[1]))); +} diff --git a/Correction/sam/ex02/a.out b/Correction/sam/ex02/a.out new file mode 100755 index 0000000..7e871ef Binary files /dev/null and b/Correction/sam/ex02/a.out differ diff --git a/Correction/sam/ex02/ft_iterative_power.c b/Correction/sam/ex02/ft_iterative_power.c new file mode 100644 index 0000000..2fca975 --- /dev/null +++ b/Correction/sam/ex02/ft_iterative_power.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet 0) + nbr_out = nbr_out * nb; + return (nbr_out); +} + +#include +#include + +int main(int argc, char **argv) +{ + if (argc > 2) + printf("%d", ft_iterative_power(atoi(argv[1]), atoi(argv[2]))); +} diff --git a/Correction/sam/ex03/a.out b/Correction/sam/ex03/a.out new file mode 100755 index 0000000..3ad1e28 Binary files /dev/null and b/Correction/sam/ex03/a.out differ diff --git a/Correction/sam/ex03/ft_recursive_power.c b/Correction/sam/ex03/ft_recursive_power.c new file mode 100644 index 0000000..5496ec8 --- /dev/null +++ b/Correction/sam/ex03/ft_recursive_power.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main(int argc, char **argv) +{ + if (argc > 2) + printf("%d", ft_recursive_power(atoi(argv[1]), atoi(argv[2]))); +} diff --git a/Correction/sam/ex04/a.out b/Correction/sam/ex04/a.out new file mode 100755 index 0000000..025f17b Binary files /dev/null and b/Correction/sam/ex04/a.out differ diff --git a/Correction/sam/ex04/ft_fibonacci.c b/Correction/sam/ex04/ft_fibonacci.c new file mode 100644 index 0000000..36f39c9 --- /dev/null +++ b/Correction/sam/ex04/ft_fibonacci.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_fibonacci.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + +int main(int argc, char **argv) +{ + if (argc > 1) + printf("%d", ft_fibonacci(atoi(argv[1]))); +} diff --git a/Correction/sam/ex05/ft_sqrt.c b/Correction/sam/ex05/ft_sqrt.c new file mode 100644 index 0000000..6650037 --- /dev/null +++ b/Correction/sam/ex05/ft_sqrt.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sqrt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include +int main(int argc, char **argv) +{ + if (argc > 1) + printf("%d", ft_is_prime(atoi(argv[1]))); +} + diff --git a/Correction/sam/ex07/a.out b/Correction/sam/ex07/a.out new file mode 100755 index 0000000..79447de Binary files /dev/null and b/Correction/sam/ex07/a.out differ diff --git a/Correction/sam/ex07/ft_find_next_prime.c b/Correction/sam/ex07/ft_find_next_prime.c new file mode 100644 index 0000000..9952b1f --- /dev/null +++ b/Correction/sam/ex07/ft_find_next_prime.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_next_prime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include +int main(int argc, char **argv) +{ + if (argc > 1) + printf("%d", ft_find_next_prime(atoi(argv[1]))); +} diff --git a/Correction/thelleg/ex00/ft_print_program_name.c b/Correction/thelleg/ex00/ft_print_program_name.c new file mode 100644 index 0000000..c7ad46d --- /dev/null +++ b/Correction/thelleg/ex00/ft_print_program_name.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_program_name.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + if (argc > 0) + print(argv[0]); +} diff --git a/Correction/thelleg/ex01/ft_print_params.c b/Correction/thelleg/ex01/ft_print_params.c new file mode 100644 index 0000000..d6da8c7 --- /dev/null +++ b/Correction/thelleg/ex01/ft_print_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + print(argv[i]); + print("\n"); + i++; + } +} diff --git a/Correction/thelleg/ex02/ft_rev_params.c b/Correction/thelleg/ex02/ft_rev_params.c new file mode 100644 index 0000000..f406582 --- /dev/null +++ b/Correction/thelleg/ex02/ft_rev_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(int argc, char **argv) +{ + int i; + + i = argc - 1; + while (i > 0) + { + print(argv[i]); + print("\n"); + i--; + } +} diff --git a/Correction/thelleg/ex03/ft_sort_params.c b/Correction/thelleg/ex03/ft_sort_params.c new file mode 100644 index 0000000..36748a6 --- /dev/null +++ b/Correction/thelleg/ex03/ft_sort_params.c @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int ft_strcmp(char *s1, char *s2) +{ + while ((*s1 != 0) && (*s2 != 0) && (*s1 == *s2)) + { + s1++; + s2++; + } + return (*s1 - *s2); +} + +int ft_get_size(char *str) +{ + int i; + + i = 0; + while (str[i] != 0) + i++; + return (i); +} + +void ft_sort_int_tab(char **tab, int size) +{ + int i; + int j; + char *tempo; + + i = 0; + while (i < size) + { + j = 0; + while (j < size - 1) + { + if (ft_strcmp(tab[j], tab[j + 1]) > 0) + { + tempo = tab[j]; + tab[j] = tab[j + 1]; + tab[j + 1] = tempo; + } + j++; + } + i++; + } +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + ft_sort_int_tab(argv + 1, argc - 1); + while (i < argc) + { + ft_print(argv[i]); + ft_print("\n"); + i++; + } +} diff --git a/Correction/thellego/a.out b/Correction/thellego/a.out new file mode 100755 index 0000000..b757530 Binary files /dev/null and b/Correction/thellego/a.out differ diff --git a/Correction/thellego/ex00/ft_strcpy.c b/Correction/thellego/ex00/ft_strcpy.c new file mode 100644 index 0000000..c840523 --- /dev/null +++ b/Correction/thellego/ex00/ft_strcpy.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/16 13:44:49 by thellego #+# #+# */ +/* Updated: 2022/07/20 10:51:58 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +char *ft_strcpy(char *dest, char *src) +{ + int counter; + + counter = 0; + while (*src != '\0') + { + + dest[counter] = src[counter]; + counter++; + } + dest[counter] = '\0'; + return (dest); +} + +int main() +{ + + char tab1[120] = "Hello world jjhaflhsuid ai;eiwjejvhds jdg"; + char tab[120] = ""; + + tab1[0] = 8; + ft_strcpy(tab, tab1); + printf("%s\n", tab1); + printf("%s\n", tab); +} diff --git a/Correction/thellego/ex01/ft_strncpy.c b/Correction/thellego/ex01/ft_strncpy.c new file mode 100644 index 0000000..ea23d85 --- /dev/null +++ b/Correction/thellego/ex01/ft_strncpy.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 09:22:49 by thellego #+# #+# */ +/* Updated: 2022/07/20 10:53:02 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *dest, char *src, unsigned int n) +{ + unsigned int counter; + + counter = 0; + while (counter < n && src[counter] != '\0') + { + dest[counter] = src[counter]; + counter++; + } + while (counter < n) + { + dest[counter] = '\0'; + counter++; + } + if (src[counter] == '\0') + dest[counter] = '\0'; + return (dest); +} + +#include + int main() +{ + char tab1[120] = "hello world jjhaflhsuid ai;eiwjejvhds jdg"; + char tab[120] = ""; + printf("%s\n", tab); + ft_strncpy(tab, tab1, 10); + printf("%s\n", tab1); + printf("%s\n", tab); +} diff --git a/Correction/thellego/ex02/ft_str_is_alpha.c b/Correction/thellego/ex02/ft_str_is_alpha.c new file mode 100644 index 0000000..417c825 --- /dev/null +++ b/Correction/thellego/ex02/ft_str_is_alpha.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 09:49:06 by thellego #+# #+# */ +/* Updated: 2022/07/17 19:21:41 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_alpha(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if ((65 <= str[counter] && str[counter] <= 90) + || (97 <= str[counter] && str[counter] <= 122)) + { + counter++; + } + else + { + return (0); + } + } + return (1); +} diff --git a/Correction/thellego/ex03/ft_str_is_numeric.c b/Correction/thellego/ex03/ft_str_is_numeric.c new file mode 100644 index 0000000..f0ff52d --- /dev/null +++ b/Correction/thellego/ex03/ft_str_is_numeric.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 10:43:58 by thellego #+# #+# */ +/* Updated: 2022/07/17 10:54:48 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_numeric(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if (48 <= str[counter] && str[counter] <= 57) + { + counter++; + } + else + { + return (0); + } + } + return (1); +} +/* int main() +{ + char tab1[120] = "0123456789iiiiijd;s"; + ft_str_is_numeric(tab1); +}*/ diff --git a/Correction/thellego/ex04/ft_str_is_lowercase.c b/Correction/thellego/ex04/ft_str_is_lowercase.c new file mode 100644 index 0000000..6a15fe4 --- /dev/null +++ b/Correction/thellego/ex04/ft_str_is_lowercase.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 12:01:10 by thellego #+# #+# */ +/* Updated: 2022/07/17 12:09:09 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_lowercase(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if (97 <= str[counter] && str[counter] <= 122) + { + counter++; + } + else + { + return (0); + } + } + return (1); +} +/* int main() +{ + char tab1[120] = "hello world"; + ft_str_is_lowercase(tab1); +} */ diff --git a/Correction/thellego/ex05/ft_str_is_uppercase.c b/Correction/thellego/ex05/ft_str_is_uppercase.c new file mode 100644 index 0000000..44c45af --- /dev/null +++ b/Correction/thellego/ex05/ft_str_is_uppercase.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_uppercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 12:10:02 by thellego #+# #+# */ +/* Updated: 2022/07/17 12:14:24 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_uppercase(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if (65 <= str[counter] && str[counter] <= 90) + { + counter++; + } + else + { + return (0); + } + } + return (1); +} +/* int main() +{ + char tab1[120] = "QWERTYUIOPASDFGHJKLZXCVBNMeL"; + ft_str_is_uppercase(tab1); +}*/ diff --git a/Correction/thellego/ex06/ft_str_is_printable.c b/Correction/thellego/ex06/ft_str_is_printable.c new file mode 100644 index 0000000..abbb6e4 --- /dev/null +++ b/Correction/thellego/ex06/ft_str_is_printable.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 12:17:42 by thellego #+# #+# */ +/* Updated: 2022/07/17 20:32:27 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_printable(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if (32 <= str[counter] && str[counter] <= 126) + { + counter++; + } + else + { + return (0); + } + } + return (1); +} +/* int main(){ + char tab1[120] = "QW ERklzxcvbnm,./;'][=-0987654321`~!@#$%^&*()_+}{"; + ft_str_is_printable(tab1); +} */ diff --git a/Correction/thellego/ex07/ft_strupcase.c b/Correction/thellego/ex07/ft_strupcase.c new file mode 100644 index 0000000..75d99f5 --- /dev/null +++ b/Correction/thellego/ex07/ft_strupcase.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strupcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 12:25:28 by thellego #+# #+# */ +/* Updated: 2022/07/17 13:06:29 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strupcase(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if (97 <= str[counter] && str[counter] <= 122) + str[counter] = str[counter] - 32; + counter++; + } + return (str); +} +/* int main(){ + char tab1[120] = "Hyurga uriaujhdljhnb9"; + ft_strupcase(tab1); + printf("%s", tab1); +} */ diff --git a/Correction/thellego/ex08/ft_strlowcase.c b/Correction/thellego/ex08/ft_strlowcase.c new file mode 100644 index 0000000..6362a26 --- /dev/null +++ b/Correction/thellego/ex08/ft_strlowcase.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlowcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 13:07:13 by thellego #+# #+# */ +/* Updated: 2022/07/17 13:10:03 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strlowcase(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if (65 <= str[counter] && str[counter] <= 90) + str[counter] = str[counter] + 32; + counter++; + } + return (str); +} +/* int main(){ + char tab1[120] = "Hfdh HELLO WORLD /.,'[-009"; + ft_strlowcase(tab1); + printf("%s", tab1); +} */ diff --git a/Correction/thellego/ex09/ft_strcapitalize.c b/Correction/thellego/ex09/ft_strcapitalize.c new file mode 100644 index 0000000..443b4db --- /dev/null +++ b/Correction/thellego/ex09/ft_strcapitalize.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcapitalize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/17 15:19:23 by thellego #+# #+# */ +/* Updated: 2022/07/20 10:59:02 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include +char *ft_strcapitalize(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + { + if (counter == 0) + { + if (97 <= str[counter] && str[counter] <= 122) + { + str[counter] = str[counter] - 32; + } + } + if (97 <= str[counter] && str[counter] <= 122) + { + if ((32 <= str[counter - 1] && str[counter - 1] <= 47) + || (58 <= str[counter - 1] && str[counter - 1] <= 64) + || (91 <= str[counter - 1] && str[counter - 1] <= 96) + || (123 <= str[counter - 1] && str[counter - 1] <= 126)) + { + str[counter] = str[counter] - 32; + } + } + counter++; + } + return (str); +} + + int main(){ + char tab[90] = "salut, cOmment tu vas ? 42mots quarante-deux; cinquante+et+un"; + ft_strcapitalize(tab); + printf("%s", tab); +} + diff --git a/Correction/thellego/ex10/ft_strlcpy.c b/Correction/thellego/ex10/ft_strlcpy.c new file mode 100644 index 0000000..0893f75 --- /dev/null +++ b/Correction/thellego/ex10/ft_strlcpy.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/18 09:44:45 by thellego #+# #+# */ +/* Updated: 2022/07/20 11:02:34 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +unsigned int ft_strlcpy(char *dest, char *src, unsigned int size) +{ + unsigned int i; + + i = 0; + while (i < size - 1 && src[i] != '\0') + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + while (src[i] != '\0') + { + i++; + } + return (i); +} + int main() +{ + char tab1[12] = "hello world"; + char tab[5] = ""; + printf("%s\n", tab); + printf("%d\n", ft_strlcpy(tab, tab1, 11)); + printf("%s\n", tab1); + printf("%s\n", tab); +} diff --git a/Correction/thellego/ex11/ft_putstr_non_printable.c b/Correction/thellego/ex11/ft_putstr_non_printable.c new file mode 100644 index 0000000..231df66 --- /dev/null +++ b/Correction/thellego/ex11/ft_putstr_non_printable.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_non_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: thellego +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/18 15:54:18 by thellego #+# #+# */ +/* Updated: 2022/07/18 22:39:25 by thellego ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_printhexa(int i) +{ + int nb; + + nb = i / 16; + write(1, "\\", 1); + write(1, &"0123456789abcdef"[nb % 16], 1); + write(1, &"0123456789abcdef"[i % 16], 1); +} + +void ft_putstr_non_printable(char *str) +{ + int i; + + i = 0; + while (str[i]) + { + if (str[i] >= 32 && str[i] <= 126) + write(1, &str[i], 1); + else + ft_printhexa(str[i]); + i++; + } +} +/*int main(void){ + ft_putstr_non_printable("Coucou\ntu vas bien ?"); +}*/ diff --git a/Correction/titou/ex00/a.out b/Correction/titou/ex00/a.out new file mode 100755 index 0000000..5cdbb30 Binary files /dev/null and b/Correction/titou/ex00/a.out differ diff --git a/Correction/titou/ex00/ft_strcmp.c b/Correction/titou/ex00/ft_strcmp.c new file mode 100644 index 0000000..aa28197 --- /dev/null +++ b/Correction/titou/ex00/ft_strcmp.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +int main(){ + char tab[] = "camille est beau"; + char tab2[] = "Camille est beau"; + printf("%d", ft_strcmp(tab, tab2)); +} diff --git a/Correction/titou/ex01/a.out b/Correction/titou/ex01/a.out new file mode 100755 index 0000000..5356a65 Binary files /dev/null and b/Correction/titou/ex01/a.out differ diff --git a/Correction/titou/ex01/ft_strncmp.c b/Correction/titou/ex01/ft_strncmp.c new file mode 100644 index 0000000..e5fc9b6 --- /dev/null +++ b/Correction/titou/ex01/ft_strncmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +int main(){ + char tab[] = "camille est beau"; + char tab2[] = "camille est beau"; + printf("%d", ft_strncmp(tab, tab2, 5)); +} + diff --git a/Correction/titou/ex02/a.out b/Correction/titou/ex02/a.out new file mode 100755 index 0000000..3497ab1 Binary files /dev/null and b/Correction/titou/ex02/a.out differ diff --git a/Correction/titou/ex02/ft_strcat.c b/Correction/titou/ex02/ft_strcat.c new file mode 100644 index 0000000..2e8de80 --- /dev/null +++ b/Correction/titou/ex02/ft_strcat.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +int main(){ + char tab[] = "camille est beau"; + char tab2[] = "Camille est beau"; + printf("%s", ft_strcat(tab, tab2)); +} + diff --git a/Correction/titou/ex03/a.out b/Correction/titou/ex03/a.out new file mode 100755 index 0000000..7faa78c Binary files /dev/null and b/Correction/titou/ex03/a.out differ diff --git a/Correction/titou/ex03/ft_strncat.c b/Correction/titou/ex03/ft_strncat.c new file mode 100644 index 0000000..162ad57 --- /dev/null +++ b/Correction/titou/ex03/ft_strncat.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +int main(){ + char tab[] = "camille est beau"; + char tab2[] = "Camille est beau"; + printf("%s", ft_strncat(tab, tab2, 10)); +} diff --git a/Correction/titou/ex04/a.out b/Correction/titou/ex04/a.out new file mode 100755 index 0000000..38ec832 Binary files /dev/null and b/Correction/titou/ex04/a.out differ diff --git a/Correction/titou/ex04/ft_strstr.c b/Correction/titou/ex04/ft_strstr.c new file mode 100644 index 0000000..3001131 --- /dev/null +++ b/Correction/titou/ex04/ft_strstr.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include + + +int main (void) { + char haystack1[20] = "TutorialsPointPoint"; + char needle1[10] = "Point"; + char *ret1; + + ret1 = strstr(haystack1, needle1); + + printf("The substring is: %s\n", ret1); + + + printf("\n"); + + + char haystack2[20] = "TutorialsPointPoint"; + char needle2[10] = "Point"; + char *ret2; + + ret2 = ft_strstr(haystack2, needle2); + + printf("The substring is: %s\n", ret2); + + return(0); +} + diff --git a/Correction/titou/ex05/ft_strlcat.c b/Correction/titou/ex05/ft_strlcat.c new file mode 100644 index 0000000..119055c --- /dev/null +++ b/Correction/titou/ex05/ft_strlcat.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +int main() +{ + char src[] = "hello"; + char dest2[5] = "fjff"; + int j; + + j = ft_strlcat(src, dest2, 5); + + printf("%d %s\n", j, dest2); +} diff --git a/Rush/Rush00/ex00/a.out b/Rush/Rush00/ex00/a.out new file mode 100755 index 0000000..bbc031c Binary files /dev/null and b/Rush/Rush00/ex00/a.out differ diff --git a/Rush/Rush00/ex00/ft_putchar.c b/Rush/Rush00/ex00/ft_putchar.c new file mode 100644 index 0000000..f099525 --- /dev/null +++ b/Rush/Rush00/ex00/ft_putchar.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mchedota +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/15 18:08:06 by mchedota #+# #+# */ +/* Updated: 2022/07/16 09:56:02 by mchedota ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c); + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/Rush/Rush00/ex00/main.c b/Rush/Rush00/ex00/main.c new file mode 100644 index 0000000..ba48653 --- /dev/null +++ b/Rush/Rush00/ex00/main.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mchedota +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/15 18:17:20 by mchedota #+# #+# */ +/* Updated: 2022/07/19 15:00:38 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void rush(int x, int y); + +int main(void) +{ + rush(0, 0); + return (0); +} diff --git a/Rush/Rush00/ex00/rush02.c b/Rush/Rush00/ex00/rush02.c new file mode 100644 index 0000000..aaf861c --- /dev/null +++ b/Rush/Rush00/ex00/rush02.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush02.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mchedota +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/15 18:18:02 by mchedota #+# #+# */ +/* Updated: 2022/07/16 10:02:11 by mchedota ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_putchar(char c); + +void rush(int x, int y) +{ + int flag_x; + int flag_y; + int test_x; + + flag_y = 1; + while (y >= flag_y) + { + flag_x = 1; + while (x >= flag_x) + { + test_x = flag_x == 1 || flag_x == x; + if (test_x && flag_y == 1) + ft_putchar('A'); + else if (test_x && flag_y == y) + ft_putchar('C'); + else if (test_x || (flag_y == 1 || flag_y == y)) + ft_putchar('B'); + else + ft_putchar(' '); + flag_x++; + } + ft_putchar('\n'); + flag_y++; + } +} diff --git a/Rush/Rush01/check.c b/Rush/Rush01/check.c new file mode 100644 index 0000000..364e9ed --- /dev/null +++ b/Rush/Rush01/check.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* check.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_verif_line(int nb_tower_viewable_in, int *line, int size) +{ + int i; + int j; + int nb_tower_viewable_out; + + i = 0; + j = 0; + nb_tower_viewable_out = 1; + while (i < size) + { + j = 0; + while (line[j] < line[i]) + { + if (i == j + 1) + break ; + j++; + } + if (line[j] < line[i]) + nb_tower_viewable_out++; + i++; + } + return (nb_tower_viewable_out);// == nb_tower_viewable_in); +} + + +int *ft_verif(int *tab_user, int *tab_gen, int size) +{ + int i; + int j; + int *line; + + i = 0; + line = malloc(sizeof(*line) * size); + while (i < size * 4) + { + j = 0; + while (j < size * size) + { + ft_verif_line(tab_user[i], line, size); + j++; + } + i++; + } +} diff --git a/Rush/Rush01/ft_print.c b/Rush/Rush01/ft_print.c new file mode 100644 index 0000000..b183ebf --- /dev/null +++ b/Rush/Rush01/ft_print.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jvasseur +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/24 17:09:36 by jvasseur #+# #+# */ +/* Updated: 2022/07/25 15:52:24 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_putchar(char c); + +void ft_print(int *tab) +{ + int a; + a = 0; + while(a < 16) + { + ft_putchar(tab[a] + '0'); + if ((a + 1) % 4 == 0) + ft_putchar('\n'); + else + ft_putchar(' '); + a++; + } +} diff --git a/Rush/Rush01/ft_printf.c b/Rush/Rush01/ft_printf.c new file mode 100644 index 0000000..0bf1205 --- /dev/null +++ b/Rush/Rush01/ft_printf.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/Rush/Rush01/gen.c b/Rush/Rush01/gen.c new file mode 100644 index 0000000..4f9155f --- /dev/null +++ b/Rush/Rush01/gen.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* gen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include +#include + +int *ft_gen_row(int *tab, int size, int seed, int row_number) +{ + int i; + + i = 1; + tab[0] = seed; + while (i < size) + { + tab[i] = size % (tab[i - 1] + seed + 1); + i++; + } +} + +int *ft_gen(int size) +{ + int *tab; + int i; + int seed; + + tab = malloc(sizeof(*tab) * size * size); + seed = 0; + while (seed < size * size) + { + ft_gen_row(tab, 4, seed, 1); + seed++; + } + return (tab); +} + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + diff --git a/Rush/Rush01/input.c b/Rush/Rush01/input.c new file mode 100644 index 0000000..8e48d91 --- /dev/null +++ b/Rush/Rush01/input.c @@ -0,0 +1,39 @@ +#include +#include +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int ft_input(char *str) +{ + int i; + int counter; + int *tab; + + i = 0; + counter = 1; + while (str[i] != 0) + { + if ('0' < str[i] && str[i] < '5') + counter++; + else + if (str[i] != ' ') + return (0); + i++; + } + i = 0; + tab = malloc(sizeof(tab) * counter); + counter = 0; + while (str[i] != 0) + { + if ('0' < str[i] && str[i] < '5') + { + tab[counter] = str[i] - '0'; + counter++; + } + i++; + } +} diff --git a/Rush/Rush01/main.c b/Rush/Rush01/main.c new file mode 100644 index 0000000..e7be6f1 --- /dev/null +++ b/Rush/Rush01/main.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/07/30 15:25:55 by kcarrere #+# #+# # +# Updated: 2022/07/31 19:57:59 by kcarrere ### ########.fr # +# # +# **************************************************************************** # + +NAME = rush-02 + +SRC = decompose.c \ + dictionary_checker.c \ + file_reader.c \ + ft_atoapc.c \ + ft_atoi.c \ + ft_atonbr.c \ + ft_ctoa.c \ + ft_printapc.c \ + ft_print_dicterror.c \ + ft_print_error.c \ + ft_putstr.c \ + ft_reverse_str.c \ + ft_split.c \ + ft_strcat.c \ + ft_strcmp.c \ + ft_strlen.c \ + ft_strstr.c \ + ft_tablen.c \ + ft_tabnbr.c \ + main.c + +FLAGS = -Wall -Werror -Wextra + +all: ${NAME} + +$(NAME): + gcc -o ${NAME} ${SRC} -Iincludes ${FLAGS} + +clean: + rm -f *.o + +fclean: clean + rm -f ${NAME} + +.PHONY: all clean fclean diff --git a/Rush/Rush02/ex00/decompose.c b/Rush/Rush02/ex00/decompose.c new file mode 100644 index 0000000..9b24064 --- /dev/null +++ b/Rush/Rush02/ex00/decompose.c @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* decompose.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet '0') + { + if ((ft_strlen(nbr) - *c) % 3 == 0) + { + tab[(*i)++] = ctoa(nbr[*c], 2); + tab[*i] = malloc(sizeof(**tab) * 20); + tab[(*i)++] = "100"; + } + else if ((ft_strlen(nbr) - *c) % 3 == 2) + { + if (nbr[*c] == '1') + { + if (nbr[*c + 1] > '0') + { + tab[(*i)++] = cat(ctoa(nbr[*c], 3), ctoa(nbr[*c + 1], 2)); + *c = *c + 1; + } + } + else + tab[(*i)++] = cat(ctoa(nbr[*c], 3), "0"); + } + else + tab[(*i)++] = ctoa(nbr[*c], 2); + } +} + +void ft_last_value(char **str, int *i) +{ + str[*i] = malloc(sizeof(**str)); + str[*i] = ""; +} + +char **ft_decompose(char *nbr) +{ + unsigned int packets; + int *i; + int *c; + char **tab; + + i = malloc(sizeof(*i)); + *i = 0; + c = malloc(sizeof(*i)); + *c = 0; + tab = malloc(sizeof(*tab) * 20); + packets = ft_strlen(nbr) / 3 + ((ft_strlen(nbr) % 3) != 0); + while (nbr[*c] != '\0') + { + ft_decompose_by_char(tab, i, c, nbr); + if (packets > 1) + { + if ((ft_strlen(nbr) - *c) % 3 == 1) + { + tab[*i] = malloc(sizeof(**tab) * 20); + tab[*i] = ft_power_of_ten(ft_strlen(nbr) - *c); + } + } + *c += 1; + } + ft_last_value(tab, i); + return (tab); +} diff --git a/Rush/Rush02/ex00/dictionary_checker.c b/Rush/Rush02/ex00/dictionary_checker.c new file mode 100644 index 0000000..282bfb1 --- /dev/null +++ b/Rush/Rush02/ex00/dictionary_checker.c @@ -0,0 +1,114 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dictionary_checker.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0' && str[i] <= '9') + i++; + str_out = malloc(sizeof(*str) * (i + 1)); + i = 0; + while (str[i] >= '0' && str[i] <= '9') + { + str_out[i] = str[i]; + i++; + } + str_out[i] = '\0'; + return (str_out); +} diff --git a/Rush/Rush02/ex00/ft_ctoa.c b/Rush/Rush02/ex00/ft_ctoa.c new file mode 100644 index 0000000..73fda44 --- /dev/null +++ b/Rush/Rush02/ex00/ft_ctoa.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ctoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = '0' && str[i] <= '9') && str[i] != ' ') + return (0); + } + return (1); +} + +int ft_print_dicterror(char *str) +{ + if (ft_nbr_error(str) == 0) + { + return (0); + } + return (1); +} diff --git a/Rush/Rush02/ex00/ft_print_error.c b/Rush/Rush02/ex00/ft_print_error.c new file mode 100644 index 0000000..4bbf72e --- /dev/null +++ b/Rush/Rush02/ex00/ft_print_error.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nlauvray + +void ft_putstr(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} diff --git a/Rush/Rush02/ex00/ft_reverse_str.c b/Rush/Rush02/ex00/ft_reverse_str.c new file mode 100644 index 0000000..7d2bab7 --- /dev/null +++ b/Rush/Rush02/ex00/ft_reverse_str.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_reverse_str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nlauvray i) + { + k = i; + tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1)); + while (i < k + ft_strstr(&str[k], sep)) + { + tab[j][i - k] = str[i]; + i++; + } + tab[j][i - k] = '\0'; + i = k + ft_strstr(&str[k], sep) + ft_strlen(sep); + j++; + } + tab[j] = malloc(sizeof(char)); + tab[j] = ""; + return (tab); +} diff --git a/Rush/Rush02/ex00/ft_strcat.c b/Rush/Rush02/ex00/ft_strcat.c new file mode 100644 index 0000000..5a09174 --- /dev/null +++ b/Rush/Rush02/ex00/ft_strcat.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet = 2 && argc <= 3)) + { + write (1, "Error\n", 6); + return (0); + } + if (argc == 3) + { + i = 2; + if (ft_dict_validator(argv[1]) == 0) + return (0); + dict = ft_dictionnary_reader(argv[1]); + } + else + dict = ft_dictionnary_reader(PATH); + if (dict == NULL || ft_print_errors(argv[i]) == 0) + return (0); + tab = ft_decompose(argv[i]); + ft_printapc(tab, dict); + free(tab); + free(dict); +} diff --git a/Rush/Rush02/ex00/numbers.dict b/Rush/Rush02/ex00/numbers.dict new file mode 100644 index 0000000..d894010 --- /dev/null +++ b/Rush/Rush02/ex00/numbers.dict @@ -0,0 +1,41 @@ +0: zero +1: one +2: two +3: three +4: four +5: five +6: six +7: seven +8: eight +9: nine +10: ten +11: eleven +12: twelve +13: thirteen +14: fourteen +15: fifteen +16: sixteen +17: seventeen +18: eighteen +19: nineteen +20: twenty +30: thirty +40: forty +50: fifty +60: sixty +70: seventy +80: eighty +90: ninety +100: hundred +1000: thousand +1000000: million +1000000000: billion +1000000000000: trillion +1000000000000000: quadrillion +1000000000000000000: quintillion +1000000000000000000000: sextillion +1000000000000000000000000: septillion +1000000000000000000000000000: octillion +1000000000000000000000000000000: nonillion +1000000000000000000000000000000000: decillion +1000000000000000000000000000000000000: undecillion diff --git a/Rush/Rush02/ex00/rush02.h b/Rush/Rush02/ex00/rush02.h new file mode 100644 index 0000000..449c826 --- /dev/null +++ b/Rush/Rush02/ex00/rush02.h @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush02.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +# include +# include +# include +# include +# include +# define PATH "./numbers.dict" +# define LINES_NEED 41 + +struct s_number +{ + char *nbr; + char *apc; +}; +int ft_strcmp(char *str1, char *str2); +int ft_print_dicterror(char *str); +typedef struct s_number t_number; +char *cat(char *dest, char *src); +char *ctoa(char c, unsigned int size); +int ft_lines_counter(char **strs); +int ft_lenght(unsigned int nb); +int ft_dict_validator(char *path); +t_number *ft_dictionnary_reader(char *path); +int ft_dict_is_valid(char *path); +int ft_strstr(char *str, char *to_find); +char *ft_atonbr(char *str); +char *ft_atoapc(char *str); +char *ft_filereader(char *path); +char **ft_split(char *str, char *charset); +int ft_strlen(char *str); +int ft_tablen(t_number *tab); +unsigned int ft_atoi(char *str); +char *ft_reverse_str(char *str); +void ft_putstr(char *str); +char *ft_tabnbr(unsigned int nb); +int ft_print_errors(char *str); +void ft_printapc(char **tab, t_number *dict); +char **ft_decompose(char *nbr); + +#endif diff --git a/Rush/Rush02/ex00/rush02.h.gch b/Rush/Rush02/ex00/rush02.h.gch new file mode 100644 index 0000000..c6688a7 Binary files /dev/null and b/Rush/Rush02/ex00/rush02.h.gch differ diff --git a/Shell/shell00v4/.gitignore b/Shell/shell00v4/.gitignore new file mode 100644 index 0000000..653f160 --- /dev/null +++ b/Shell/shell00v4/.gitignore @@ -0,0 +1 @@ +test.* diff --git a/Shell/shell00v4/ex00/z b/Shell/shell00v4/ex00/z new file mode 100644 index 0000000..e900b1c --- /dev/null +++ b/Shell/shell00v4/ex00/z @@ -0,0 +1 @@ +Z diff --git a/Shell/shell00v4/ex01/testShell00.tar b/Shell/shell00v4/ex01/testShell00.tar new file mode 100644 index 0000000..768ba4c Binary files /dev/null and b/Shell/shell00v4/ex01/testShell00.tar differ diff --git a/Shell/shell00v4/ex02/exo2.tar b/Shell/shell00v4/ex02/exo2.tar new file mode 100644 index 0000000..3b120c1 Binary files /dev/null and b/Shell/shell00v4/ex02/exo2.tar differ diff --git a/Shell/shell00v4/ex03/id_rsa_pub b/Shell/shell00v4/ex03/id_rsa_pub new file mode 100644 index 0000000..f6b2709 --- /dev/null +++ b/Shell/shell00v4/ex03/id_rsa_pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVFAFTknn54lP0pzgOREzw4TGHKBrRrmEBGTSDexXftgNc/FmlXlxHT5mVLIP6ftLi/uzLYC0KoKyBZ1Kgk7gLnO9a/6h3fszZSZhwVrsQOqX3eHG90p6QzOGyBbHYQ+Z31Na0WZZ2bQX29Pm5D2PGyteJ1CNmc8/raw1QCkGgwW5H265CK3XWjaqy8tOFUMoFrDdOM62e75U0SdAQ5diZxeyLXM06jiZ/L2w/PRp1T1oFVrMyUSwMaekYceL23Rqrx7jjXarDItv+tFq1CJAhkm8A4ugZN4qi2I8hKIDQ6pTMOmawh8wVCvA+HxY8MMotAE5mOLfh0C4bAaQ8XO1VkLfzaC96v/qcrn/hKLuoMKjIf0JuXNVJBAPKZhEI9WenKBBI3LiodbCltWgM1zscQy1MyuIzVUWqOjLeNDBCBvR3vtk+KKGI5w7vpxVpYbQ9h3yY68O4uRDzvd430M+O0m5wr5N/KXSxRc9NcNKJFJj+e9T/CqjUQYV/2gCmKtU= cchauvet@2E2.42angouleme.fr diff --git a/Shell/shell00v4/ex04/midLS b/Shell/shell00v4/ex04/midLS new file mode 100644 index 0000000..a94b16a --- /dev/null +++ b/Shell/shell00v4/ex04/midLS @@ -0,0 +1 @@ +ls -tpm diff --git a/Shell/shell00v4/ex05/git_commit.sh b/Shell/shell00v4/ex05/git_commit.sh new file mode 100644 index 0000000..b888a98 --- /dev/null +++ b/Shell/shell00v4/ex05/git_commit.sh @@ -0,0 +1,2 @@ +#!/bin/sh +git log -5 --pretty=%H diff --git a/Shell/shell00v4/ex06/git_ignore.sh b/Shell/shell00v4/ex06/git_ignore.sh new file mode 100644 index 0000000..8acb9eb --- /dev/null +++ b/Shell/shell00v4/ex06/git_ignore.sh @@ -0,0 +1,2 @@ +#!/bin/sh +git status -s --ignored | grep '!!' | cut -c 4- diff --git a/Shell/shell00v4/ex07/b b/Shell/shell00v4/ex07/b new file mode 100644 index 0000000..c2dab24 --- /dev/null +++ b/Shell/shell00v4/ex07/b @@ -0,0 +1,11 @@ +Episode V, A NEW H0PE It is a period of civil war +Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. +During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the STAR DEATH, an armored space station with enough power to destroy an entire planet. + + +Pursued by the Empire's sinister agents, +Princess Mehdi races home aboard her starship, custodian of the stolen plans that can save her people and restore the dictatorship to the galaxie.. + + + + diff --git a/Shell/shell00v4/ex08/clean b/Shell/shell00v4/ex08/clean new file mode 100644 index 0000000..6381f5e --- /dev/null +++ b/Shell/shell00v4/ex08/clean @@ -0,0 +1 @@ +find . -iname "*~" -type f -print -delete -o -iname "#*#" -type f -print -delete diff --git a/Shell/shell00v5/ex00/z b/Shell/shell00v5/ex00/z new file mode 100644 index 0000000..e900b1c --- /dev/null +++ b/Shell/shell00v5/ex00/z @@ -0,0 +1 @@ +Z diff --git a/Shell/shell00v5/ex01/testShell00.tar b/Shell/shell00v5/ex01/testShell00.tar new file mode 100644 index 0000000..768ba4c Binary files /dev/null and b/Shell/shell00v5/ex01/testShell00.tar differ diff --git a/Shell/shell00v5/ex02/exo2.tar b/Shell/shell00v5/ex02/exo2.tar new file mode 100644 index 0000000..3b120c1 Binary files /dev/null and b/Shell/shell00v5/ex02/exo2.tar differ diff --git a/Shell/shell00v5/ex03/id_rsa_pub b/Shell/shell00v5/ex03/id_rsa_pub new file mode 100644 index 0000000..f6b2709 --- /dev/null +++ b/Shell/shell00v5/ex03/id_rsa_pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVFAFTknn54lP0pzgOREzw4TGHKBrRrmEBGTSDexXftgNc/FmlXlxHT5mVLIP6ftLi/uzLYC0KoKyBZ1Kgk7gLnO9a/6h3fszZSZhwVrsQOqX3eHG90p6QzOGyBbHYQ+Z31Na0WZZ2bQX29Pm5D2PGyteJ1CNmc8/raw1QCkGgwW5H265CK3XWjaqy8tOFUMoFrDdOM62e75U0SdAQ5diZxeyLXM06jiZ/L2w/PRp1T1oFVrMyUSwMaekYceL23Rqrx7jjXarDItv+tFq1CJAhkm8A4ugZN4qi2I8hKIDQ6pTMOmawh8wVCvA+HxY8MMotAE5mOLfh0C4bAaQ8XO1VkLfzaC96v/qcrn/hKLuoMKjIf0JuXNVJBAPKZhEI9WenKBBI3LiodbCltWgM1zscQy1MyuIzVUWqOjLeNDBCBvR3vtk+KKGI5w7vpxVpYbQ9h3yY68O4uRDzvd430M+O0m5wr5N/KXSxRc9NcNKJFJj+e9T/CqjUQYV/2gCmKtU= cchauvet@2E2.42angouleme.fr diff --git a/Shell/shell00v5/ex04/midLS b/Shell/shell00v5/ex04/midLS new file mode 100644 index 0000000..a94b16a --- /dev/null +++ b/Shell/shell00v5/ex04/midLS @@ -0,0 +1 @@ +ls -tpm diff --git a/Shell/shell00v5/ex05/git_commit.sh b/Shell/shell00v5/ex05/git_commit.sh new file mode 100644 index 0000000..b888a98 --- /dev/null +++ b/Shell/shell00v5/ex05/git_commit.sh @@ -0,0 +1,2 @@ +#!/bin/sh +git log -5 --pretty=%H diff --git a/Shell/shell00v5/ex06/git_ignore.sh b/Shell/shell00v5/ex06/git_ignore.sh new file mode 100644 index 0000000..8acb9eb --- /dev/null +++ b/Shell/shell00v5/ex06/git_ignore.sh @@ -0,0 +1,2 @@ +#!/bin/sh +git status -s --ignored | grep '!!' | cut -c 4- diff --git a/Shell/shell00v5/ex07/b b/Shell/shell00v5/ex07/b new file mode 100644 index 0000000..c2dab24 --- /dev/null +++ b/Shell/shell00v5/ex07/b @@ -0,0 +1,11 @@ +Episode V, A NEW H0PE It is a period of civil war +Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. +During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the STAR DEATH, an armored space station with enough power to destroy an entire planet. + + +Pursued by the Empire's sinister agents, +Princess Mehdi races home aboard her starship, custodian of the stolen plans that can save her people and restore the dictatorship to the galaxie.. + + + + diff --git a/Shell/shell00v5/ex08/clean b/Shell/shell00v5/ex08/clean new file mode 100644 index 0000000..6381f5e --- /dev/null +++ b/Shell/shell00v5/ex08/clean @@ -0,0 +1 @@ +find . -iname "*~" -type f -print -delete -o -iname "#*#" -type f -print -delete diff --git a/Shell/shell01v3/ex01/print_groups.sh b/Shell/shell01v3/ex01/print_groups.sh new file mode 100644 index 0000000..f69e4f9 --- /dev/null +++ b/Shell/shell01v3/ex01/print_groups.sh @@ -0,0 +1 @@ +id -Gn $FT_USER | tr " " "," | tr -d "\n" diff --git a/Shell/shell01v3/ex02/find_sh.sh b/Shell/shell01v3/ex02/find_sh.sh new file mode 100755 index 0000000..05ac888 --- /dev/null +++ b/Shell/shell01v3/ex02/find_sh.sh @@ -0,0 +1,2 @@ +#!/bin/sh +basename -s .sh $(find . -type f -name *.sh) diff --git a/Shell/shell01v3/ex03/count_files.sh b/Shell/shell01v3/ex03/count_files.sh new file mode 100755 index 0000000..ac16053 --- /dev/null +++ b/Shell/shell01v3/ex03/count_files.sh @@ -0,0 +1 @@ +find . -type f,d | wc -l diff --git a/Shell/shell01v3/ex04/MAC.sh b/Shell/shell01v3/ex04/MAC.sh new file mode 100644 index 0000000..862c8fb --- /dev/null +++ b/Shell/shell01v3/ex04/MAC.sh @@ -0,0 +1 @@ +ifconfig | grep ether | awk '{print $2}' diff --git "a/Shell/shell01v3/ex05/\"\\?$*'MaRViN'*$?\\\"" "b/Shell/shell01v3/ex05/\"\\?$*'MaRViN'*$?\\\"" new file mode 100644 index 0000000..f70d7bb --- /dev/null +++ "b/Shell/shell01v3/ex05/\"\\?$*'MaRViN'*$?\\\"" @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/Shell/shell01v3/ex06/skip.sh b/Shell/shell01v3/ex06/skip.sh new file mode 100644 index 0000000..832c7f9 --- /dev/null +++ b/Shell/shell01v3/ex06/skip.sh @@ -0,0 +1 @@ +ls -l | awk 'NR%2==1' diff --git a/Shell/shell01v4_check/ex01/print_groups.sh b/Shell/shell01v4_check/ex01/print_groups.sh new file mode 100644 index 0000000..f69e4f9 --- /dev/null +++ b/Shell/shell01v4_check/ex01/print_groups.sh @@ -0,0 +1 @@ +id -Gn $FT_USER | tr " " "," | tr -d "\n" diff --git a/Shell/shell01v4_check/ex02/find_sh.sh b/Shell/shell01v4_check/ex02/find_sh.sh new file mode 100755 index 0000000..05ac888 --- /dev/null +++ b/Shell/shell01v4_check/ex02/find_sh.sh @@ -0,0 +1,2 @@ +#!/bin/sh +basename -s .sh $(find . -type f -name *.sh) diff --git a/Shell/shell01v4_check/ex03/count_files.sh b/Shell/shell01v4_check/ex03/count_files.sh new file mode 100755 index 0000000..ac16053 --- /dev/null +++ b/Shell/shell01v4_check/ex03/count_files.sh @@ -0,0 +1 @@ +find . -type f,d | wc -l diff --git a/Shell/shell01v4_check/ex04/MAC.sh b/Shell/shell01v4_check/ex04/MAC.sh new file mode 100644 index 0000000..862c8fb --- /dev/null +++ b/Shell/shell01v4_check/ex04/MAC.sh @@ -0,0 +1 @@ +ifconfig | grep ether | awk '{print $2}' diff --git "a/Shell/shell01v4_check/ex05/\"\\?$*'MaRViN'*$?\\\"" "b/Shell/shell01v4_check/ex05/\"\\?$*'MaRViN'*$?\\\"" new file mode 100644 index 0000000..f70d7bb --- /dev/null +++ "b/Shell/shell01v4_check/ex05/\"\\?$*'MaRViN'*$?\\\"" @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/Shell/shell01v4_check/ex06/skip.sh b/Shell/shell01v4_check/ex06/skip.sh new file mode 100644 index 0000000..832c7f9 --- /dev/null +++ b/Shell/shell01v4_check/ex06/skip.sh @@ -0,0 +1 @@ +ls -l | awk 'NR%2==1' diff --git a/Shell/shell01v5.tar b/Shell/shell01v5.tar new file mode 100644 index 0000000..0457871 Binary files /dev/null and b/Shell/shell01v5.tar differ diff --git a/Shell/shell01v5/ex01/print_groups.sh b/Shell/shell01v5/ex01/print_groups.sh new file mode 100644 index 0000000..f69e4f9 --- /dev/null +++ b/Shell/shell01v5/ex01/print_groups.sh @@ -0,0 +1 @@ +id -Gn $FT_USER | tr " " "," | tr -d "\n" diff --git a/Shell/shell01v5/ex02/find_sh.sh b/Shell/shell01v5/ex02/find_sh.sh new file mode 100755 index 0000000..40e9a49 --- /dev/null +++ b/Shell/shell01v5/ex02/find_sh.sh @@ -0,0 +1,2 @@ +#!/bin/sh +basename -s .sh $(find . -type f -name "*.sh") diff --git a/Shell/shell01v5/ex03/count_files.sh b/Shell/shell01v5/ex03/count_files.sh new file mode 100755 index 0000000..ac16053 --- /dev/null +++ b/Shell/shell01v5/ex03/count_files.sh @@ -0,0 +1 @@ +find . -type f,d | wc -l diff --git a/Shell/shell01v5/ex04/MAC.sh b/Shell/shell01v5/ex04/MAC.sh new file mode 100644 index 0000000..862c8fb --- /dev/null +++ b/Shell/shell01v5/ex04/MAC.sh @@ -0,0 +1 @@ +ifconfig | grep ether | awk '{print $2}' diff --git "a/Shell/shell01v5/ex05/\"\\?$*'MaRViN'*$?\\\"" "b/Shell/shell01v5/ex05/\"\\?$*'MaRViN'*$?\\\"" new file mode 100644 index 0000000..f70d7bb --- /dev/null +++ "b/Shell/shell01v5/ex05/\"\\?$*'MaRViN'*$?\\\"" @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/Shell/shell01v5/ex06/skip.sh b/Shell/shell01v5/ex06/skip.sh new file mode 100644 index 0000000..832c7f9 --- /dev/null +++ b/Shell/shell01v5/ex06/skip.sh @@ -0,0 +1 @@ +ls -l | awk 'NR%2==1' diff --git a/Test/c02.tar b/Test/c02.tar new file mode 100644 index 0000000..04df152 Binary files /dev/null and b/Test/c02.tar differ diff --git a/Test/c02/ex00/main.c b/Test/c02/ex00/main.c new file mode 100644 index 0000000..49aa4a7 --- /dev/null +++ b/Test/c02/ex00/main.c @@ -0,0 +1,21 @@ +#include + +char *ft_strcpy(char *dest, char *src); + +void ft_print(char *str) +{ + while(*str != 0) + { + write(1, str++, 1); + } +} + +int main(void) +{ + char *a; + char b[5]; + + a = "00000"; + ft_strncpy(b, a); + ft_print(b); +} diff --git a/Test/c02/ex01/main.c b/Test/c02/ex01/main.c new file mode 100644 index 0000000..db3f8a8 --- /dev/null +++ b/Test/c02/ex01/main.c @@ -0,0 +1,22 @@ +#include + +char *ft_strncpy(char *dest, char *src, unsigned int n); + +void ft_print(char *str) +{ + while(*str != 0) + { + write(1, str++, 1); + } +} + +int main(void) +{ + char *a; + char b[6]; + + b[5] = 'd'; + a = "00000"; + ft_strncpy(b, a, 5); + ft_print(b); +} diff --git a/Test/c02/ex02/main.c b/Test/c02/ex02/main.c new file mode 100644 index 0000000..8fce0f4 --- /dev/null +++ b/Test/c02/ex02/main.c @@ -0,0 +1,17 @@ +#include + +int ft_str_is_alpha(char *str); + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main(void) +{ + ft_putchar(ft_str_is_alpha("ff")+'0'); + ft_putchar(ft_str_is_alpha("dfdf5f")+'0'); + ft_putchar(ft_str_is_alpha("GDGFSGF")+48); + ft_putchar(ft_str_is_alpha("FG5DG")+48); + ft_putchar(ft_str_is_alpha("")+48); +} diff --git a/Test/c02/ex03/main.c b/Test/c02/ex03/main.c new file mode 100644 index 0000000..6fdb966 --- /dev/null +++ b/Test/c02/ex03/main.c @@ -0,0 +1,17 @@ +#include + +int ft_str_is_numeric(char *str); + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main() +{ + ft_putchar(ft_str_is_numeric("55654")+48); + ft_putchar(ft_str_is_numeric("ssdf5")+48); + ft_putchar(ft_str_is_numeric("5")+48); + ft_putchar(ft_str_is_numeric("55d654")+48); + ft_putchar(ft_str_is_numeric("")+48); +} diff --git a/Test/c02/ex04/main.c b/Test/c02/ex04/main.c new file mode 100644 index 0000000..cc19075 --- /dev/null +++ b/Test/c02/ex04/main.c @@ -0,0 +1,17 @@ +#include + +int ft_str_is_lowercase(char *str); + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main(void) +{ + ft_putchar(ft_str_is_lowercase("ff")+'0'); + ft_putchar(ft_str_is_lowercase("dfdf5f")+'0'); + ft_putchar(ft_str_is_lowercase("d")+48); + ft_putchar(ft_str_is_lowercase("FG5DG")+48); + ft_putchar(ft_str_is_lowercase("")+48); +} diff --git a/Test/c02/ex05/main.c b/Test/c02/ex05/main.c new file mode 100644 index 0000000..946aff7 --- /dev/null +++ b/Test/c02/ex05/main.c @@ -0,0 +1,18 @@ +#include + +int ft_str_is_uppercase(char *str); + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main(void) +{ + ft_putchar(ft_str_is_uppercase("AAA")+'0'); + ft_putchar(ft_str_is_uppercase("dfdf5f")+'0'); + ft_putchar(ft_str_is_uppercase("Z")+48); + ft_putchar(ft_str_is_uppercase("FG5DG")+48); + ft_putchar(ft_str_is_uppercase("")+48); +} + diff --git a/Test/c02/ex06/main.c b/Test/c02/ex06/main.c new file mode 100644 index 0000000..1c1780f --- /dev/null +++ b/Test/c02/ex06/main.c @@ -0,0 +1,17 @@ +#include + +int ft_str_is_printable(char *str); + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main(void) +{ + ft_putchar(ft_str_is_printable(" ")+48); + ft_putchar(ft_str_is_printable("\n")+48); + ft_putchar(ft_str_is_printable("~")+48); + ft_putchar(ft_str_is_printable("\b")+48); + ft_putchar(ft_str_is_printable("")+48); +} diff --git a/Test/c02/ex07/main.c b/Test/c02/ex07/main.c new file mode 100644 index 0000000..83f8b53 --- /dev/null +++ b/Test/c02/ex07/main.c @@ -0,0 +1,25 @@ +#include + +char *ft_strupcase(char *str); + +void ft_print(char *str) +{ + while (*str != 0) + write(1, str++, 1); +} + +int main(void) +{ + char a[4] = "test"; + ft_print(ft_strupcase(a)); + + char b[4] = "TEST"; + ft_print(ft_strupcase(b)); + + char c[4] = "t3st"; + ft_print(ft_strupcase(c)); + + char d[4] = "t3St"; + ft_print(ft_strupcase(d)); + +} diff --git a/Test/c03/ex00/main.c b/Test/c03/ex00/main.c new file mode 100644 index 0000000..b180c35 --- /dev/null +++ b/Test/c03/ex00/main.c @@ -0,0 +1,25 @@ +#include +#include + +int main() +{ + char src1[] = "dddd"; + char dest1[8] = "ddde"; + int result1; + + result1 = strcmp(dest1, src1); + printf("%d", result1); + + + printf("\n"); + + + char src2[] = "dddd"; + char dest2[8] = "ddde"; + int result2; + + result2 = ft_strcmp(dest2, src2); + printf("%d", result2); + return 0; +} + diff --git a/Test/c03/ex01/main.c b/Test/c03/ex01/main.c new file mode 100644 index 0000000..6839d76 --- /dev/null +++ b/Test/c03/ex01/main.c @@ -0,0 +1,25 @@ +#include +#include + +int main() +{ + char src1[] = "dddd"; + char dest1[8] = "ddde"; + int result1; + + result1 = strncmp(dest1, src1, 4); + printf("%d", result1); + + + printf("\n"); + + + char src2[] = "dddd"; + char dest2[8] = "ddde"; + int result2; + + result2 = ft_strncmp(dest2, src2, 4); + printf("%d", result2); + return 0; +} + diff --git a/Test/c03/ex02/main.c b/Test/c03/ex02/main.c new file mode 100644 index 0000000..5d83abf --- /dev/null +++ b/Test/c03/ex02/main.c @@ -0,0 +1,23 @@ +#include +#include + +int main() +{ + char src1[] = "debut"; + char dest1[8] = "fin"; + + strcat(dest1, src1); + printf(dest1); + + + printf("\n"); + + + char src2[] = "debut"; + char dest2[8] = "fin"; + + ft_strcat(dest2, src2); + printf(dest2); + return 0; +} + diff --git a/Test/c03/ex03/main.c b/Test/c03/ex03/main.c new file mode 100644 index 0000000..434fbdc --- /dev/null +++ b/Test/c03/ex03/main.c @@ -0,0 +1,29 @@ +#include +#include + +int main () { + char src1[50], dest1[50]; + + strcpy(src1, "This is source"); + strcpy(dest1, "This is destination"); + + strncat(dest1, src1, 10); + + printf("%s", dest1); + + + printf("\n"); + + + char src2[50], dest2[50]; + + strcpy(src2, "This is source"); + strcpy(dest2, "This is destination"); + + ft_strncat(dest2, src2, 10); + + printf("%s", dest2); + + return(0); +} + diff --git a/Test/c03/ex04/main.c b/Test/c03/ex04/main.c new file mode 100644 index 0000000..2926fdb --- /dev/null +++ b/Test/c03/ex04/main.c @@ -0,0 +1,28 @@ +#include +#include + + +int main (void) { + char haystack1[20] = "TutorialsPoint"; + char needle1[10] = "Point"; + char *ret1; + + ret1 = strstr(haystack1, needle1); + + printf("The substring is: %s\n", ret1); + + + printf("\n"); + + + char haystack2[20] = "TutorialsPoint"; + char needle2[10] = "Point"; + char *ret2; + + ret2 = ft_strstr(haystack2, needle2); + + printf("The substring is: %s\n", ret2); + + return(0); +} + diff --git a/Test/c03/ex05/main.c b/Test/c03/ex05/main.c new file mode 100644 index 0000000..e398aae --- /dev/null +++ b/Test/c03/ex05/main.c @@ -0,0 +1,12 @@ +#include +int main() +{ + char src[] = "hello"; + char dest2[5] = "fjff"; + int j; + + j = ft_strlcat(src, dest2, 5); + + printf("%d %s\n", j, dest2); +} + diff --git a/Test/c04/ex03/main.c b/Test/c04/ex03/main.c new file mode 100644 index 0000000..9a011d7 --- /dev/null +++ b/Test/c04/ex03/main.c @@ -0,0 +1,7 @@ +#include + +int main () +{ + printf("%d ", ft_atoi(" --++4")); +} + diff --git a/Test/c04/ex04/main.c b/Test/c04/ex04/main.c new file mode 100644 index 0000000..e086c96 --- /dev/null +++ b/Test/c04/ex04/main.c @@ -0,0 +1,5 @@ +int main() +{ + ft_putnbr_base(256, "01"); +} + diff --git a/Test/c04/ex05/main.c b/Test/c04/ex05/main.c new file mode 100644 index 0000000..96edb26 --- /dev/null +++ b/Test/c04/ex05/main.c @@ -0,0 +1,7 @@ + +#include +int main() +{ + printf("%d", ft_atoi_base(" --++kkk", "loki")); +} + diff --git a/Test/c05/ex00/main.c b/Test/c05/ex00/main.c new file mode 100644 index 0000000..2991cc2 --- /dev/null +++ b/Test/c05/ex00/main.c @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + if (argc > 1) + printf("%d", ft_iterative_factoriel(atoi(argv[1]))); +} + diff --git a/Test/c05/ex01/main.c b/Test/c05/ex01/main.c new file mode 100644 index 0000000..357c741 --- /dev/null +++ b/Test/c05/ex01/main.c @@ -0,0 +1,8 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + if (argc > 1) + printf("%d", ft_recursive_factoriel(atoi(argv[1]))); +} diff --git a/Test/c05/ex02/main.c b/Test/c05/ex02/main.c new file mode 100644 index 0000000..f1bc8e4 --- /dev/null +++ b/Test/c05/ex02/main.c @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + if (argc > 2) + printf("%d", ft_iterative_power(atoi(argv[1]), atoi(argv[2]))); +} + diff --git a/Test/c05/ex03/main.c b/Test/c05/ex03/main.c new file mode 100644 index 0000000..d2ab81e --- /dev/null +++ b/Test/c05/ex03/main.c @@ -0,0 +1,10 @@ + +#include +#include + +int main(int argc, char **argv) +{ + if (argc > 2) + printf("%d", ft_recursive_power(atoi(argv[1]), atoi(argv[2]))); +} + diff --git a/Test/c05/ex04/main.c b/Test/c05/ex04/main.c new file mode 100644 index 0000000..8377455 --- /dev/null +++ b/Test/c05/ex04/main.c @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + if (argc > 1) + printf("%d", ft_fibonacci(atoi(argv[1]))); +} + diff --git a/Test/c05/ex05/main.c b/Test/c05/ex05/main.c new file mode 100644 index 0000000..cef053e --- /dev/null +++ b/Test/c05/ex05/main.c @@ -0,0 +1,9 @@ +#include +#include +int main(int argc, char **argv) +{ + if (argc > 1) + printf("%d", ft_sqrt(atoi(argv[1]))); +} + + diff --git a/Test/c05/ex06/main.c b/Test/c05/ex06/main.c new file mode 100644 index 0000000..f5ececb --- /dev/null +++ b/Test/c05/ex06/main.c @@ -0,0 +1,8 @@ +#include +#include +int main(int argc, char **argv) +{ + if (argc > 1) + printf("%d", ft_is_prime(atoi(argv[1]))); +} + diff --git a/Test/c05/ex07/main.c b/Test/c05/ex07/main.c new file mode 100644 index 0000000..22af1f1 --- /dev/null +++ b/Test/c05/ex07/main.c @@ -0,0 +1,7 @@ +#include +#include +int main(int argc, char **argv) +{ + if (argc > 1) + printf("%d", ft_find_next_prime(atoi(argv[1]))); +} diff --git a/Test/c07.tar b/Test/c07.tar new file mode 100644 index 0000000..7b14376 Binary files /dev/null and b/Test/c07.tar differ diff --git a/Test/c07/ex00.c b/Test/c07/ex00.c new file mode 100644 index 0000000..d6fc63d --- /dev/null +++ b/Test/c07/ex00.c @@ -0,0 +1,12 @@ + +#include + +int main() +{ + char src[] = "test"; + char *dest; + dest = ft_strdup(src); + printf("%s %p \n", src, &src); + printf("%s %p \n", dest, &dest); +} + diff --git a/Test/c07/ex01.c b/Test/c07/ex01.c new file mode 100644 index 0000000..cd712d0 --- /dev/null +++ b/Test/c07/ex01.c @@ -0,0 +1,23 @@ +#include +#include +int main(int argc, char **argv) +{ + int i; + int min; + int max; + int *tab; + + if (argc > 2) + { + i = 0; + min = atoi(argv[1]); + max = atoi(argv[2]); + tab = ft_range(min, max); + while (i < max - min) + { + printf("%d, ", *(tab + i)); + i++; + } + } +} + diff --git a/Test/c07/ex02.c b/Test/c07/ex02.c new file mode 100644 index 0000000..4b0e50d --- /dev/null +++ b/Test/c07/ex02.c @@ -0,0 +1,20 @@ +#include +int main(void) +{ + int temp1; + int *temp2; + int **tab; + + temp1 = 0; + temp2 =&temp1; + tab = &temp2; + printf("%d", ft_ultimate_range(tab, 0, 10)); + printf("\n"); + for (int ind = 0; ind<10; ind++ ) + { + printf("%i, ", (*tab)[ind]); + + } + return (0); +} + diff --git a/Test/c08/ex04.c b/Test/c08/ex04.c new file mode 100644 index 0000000..1cf33de --- /dev/null +++ b/Test/c08/ex04.c @@ -0,0 +1,14 @@ +int main(int ac, char **av) +{ + t_stock_str *tab; + int i; + + tab = ft_strs_to_tab(ac, av); + i = 0; + while (i < ac) + { + printf("size = %d, str = %s, copy = %s\n", tab[i].size, tab[i].str, tab[i].copy); + i++; + } +} + diff --git a/Test/c09/ex05/ft_stock_str.h b/Test/c09/ex05/ft_stock_str.h new file mode 100644 index 0000000..6a8ce8f --- /dev/null +++ b/Test/c09/ex05/ft_stock_str.h @@ -0,0 +1,6 @@ +typedef struct s_stock_str +{ +int size; +char *str; +char *copy; +} t_stock_str; diff --git a/Test/c09/ex05/main.c b/Test/c09/ex05/main.c new file mode 100644 index 0000000..f643a0b --- /dev/null +++ b/Test/c09/ex05/main.c @@ -0,0 +1,12 @@ +#include "ft_stock_str.h" + +void ft_show_tab(struct s_stock_str *par); +struct s_stock_str *ft_strs_to_tab(int ac, char **av); + +int main(int ac, char **av) +{ + t_stock_str *tab; + + tab = ft_strs_to_tab(ac, av); + ft_show_tab(tab); +}