Repository: ChuOkupai/piscine42 Branch: main Commit: cc5e12c07768 Files: 250 Total size: 266.3 KB Directory structure: gitextract_uqh3g1tv/ ├── .gitignore ├── README.md ├── bsq/ │ ├── Makefile │ ├── auteur │ ├── gen.pl │ ├── includes/ │ │ └── ft.h │ └── srcs/ │ ├── ft_file_load.c │ ├── ft_find_biggest_square.c │ ├── ft_is_valid.c │ └── main.c ├── c00/ │ ├── ex00/ │ │ └── ft_putchar.c │ ├── ex01/ │ │ └── ft_print_alphabet.c │ ├── ex02/ │ │ └── ft_print_reverse_alphabet.c │ ├── ex03/ │ │ └── ft_print_numbers.c │ ├── ex04/ │ │ └── ft_is_negative.c │ ├── ex05/ │ │ └── ft_print_comb.c │ ├── ex06/ │ │ └── ft_print_comb2.c │ ├── ex07/ │ │ └── ft_putnbr.c │ └── ex08/ │ └── ft_print_combn.c ├── c01/ │ ├── ex00/ │ │ └── ft_ft.c │ ├── ex01/ │ │ └── ft_ultimate_ft.c │ ├── ex02/ │ │ └── ft_swap.c │ ├── ex03/ │ │ └── ft_div_mod.c │ ├── ex04/ │ │ └── ft_ultimate_div_mod.c │ ├── ex05/ │ │ └── ft_putstr.c │ ├── ex06/ │ │ └── ft_strlen.c │ ├── ex07/ │ │ └── ft_rev_int_tab.c │ └── ex08/ │ └── ft_sort_int_tab.c ├── c02/ │ ├── ex00/ │ │ └── ft_strcpy.c │ ├── ex01/ │ │ └── ft_strncpy.c │ ├── ex02/ │ │ └── ft_str_is_alpha.c │ ├── ex03/ │ │ └── ft_str_is_numeric.c │ ├── ex04/ │ │ └── ft_str_is_lowercase.c │ ├── ex05/ │ │ └── ft_str_is_uppercase.c │ ├── ex06/ │ │ └── ft_str_is_printable.c │ ├── ex07/ │ │ └── ft_strupcase.c │ ├── ex08/ │ │ └── ft_strlowcase.c │ ├── ex09/ │ │ └── ft_strcapitalize.c │ ├── ex10/ │ │ └── ft_strlcpy.c │ ├── ex11/ │ │ └── ft_putstr_non_printable.c │ └── ex12/ │ └── ft_print_memory.c ├── c03/ │ ├── ex00/ │ │ └── ft_strcmp.c │ ├── ex01/ │ │ └── ft_strncmp.c │ ├── ex02/ │ │ └── ft_strcat.c │ ├── ex03/ │ │ └── ft_strncat.c │ ├── ex04/ │ │ └── ft_strstr.c │ └── ex05/ │ └── ft_strlcat.c ├── c04/ │ ├── ex00/ │ │ └── ft_strlen.c │ ├── ex01/ │ │ └── ft_putstr.c │ ├── ex02/ │ │ └── ft_putnbr.c │ ├── ex03/ │ │ └── ft_atoi.c │ ├── ex04/ │ │ └── ft_putnbr_base.c │ └── ex05/ │ └── ft_atoi_base.c ├── c05/ │ ├── ex00/ │ │ └── ft_iterative_factorial.c │ ├── ex01/ │ │ └── ft_recursive_factorial.c │ ├── ex02/ │ │ └── ft_iterative_power.c │ ├── ex03/ │ │ └── ft_recursive_power.c │ ├── ex04/ │ │ └── ft_fibonacci.c │ ├── ex05/ │ │ └── ft_sqrt.c │ ├── ex06/ │ │ └── ft_is_prime.c │ ├── ex07/ │ │ └── ft_find_next_prime.c │ └── ex08/ │ └── ft_ten_queens_puzzle.c ├── c06/ │ ├── ex00/ │ │ └── ft_print_program_name.c │ ├── ex01/ │ │ └── ft_print_params.c │ ├── ex02/ │ │ └── ft_rev_params.c │ └── ex03/ │ └── ft_sort_params.c ├── c07/ │ ├── ex00/ │ │ └── ft_strdup.c │ ├── ex01/ │ │ └── ft_range.c │ ├── ex02/ │ │ └── ft_ultimate_range.c │ ├── ex03/ │ │ └── ft_strjoin.c │ ├── ex04/ │ │ ├── ft_convert_base.c │ │ └── ft_convert_base2.c │ └── ex05/ │ └── ft_split.c ├── c08/ │ ├── ex00/ │ │ └── ft.h │ ├── ex01/ │ │ └── ft_boolean.h │ ├── ex02/ │ │ └── ft_abs.h │ ├── ex03/ │ │ └── ft_point.h │ ├── ex04/ │ │ └── ft_strs_to_tab.c │ └── ex05/ │ └── ft_show_tab.c ├── c09/ │ ├── ex00/ │ │ ├── ft_putchar.c │ │ ├── ft_putstr.c │ │ ├── ft_strcmp.c │ │ ├── ft_strlen.c │ │ ├── ft_swap.c │ │ └── libft_creator.sh │ ├── ex01/ │ │ └── Makefile │ └── ex02/ │ └── ft_split.c ├── c10/ │ ├── ex00/ │ │ ├── Makefile │ │ ├── ft.h │ │ ├── ft_display_file.c │ │ ├── ft_putstr_fd.c │ │ ├── ft_strlen.c │ │ └── main.c │ ├── ex01/ │ │ ├── Makefile │ │ ├── ft.h │ │ ├── ft_display_file.c │ │ ├── ft_putchar_fd.c │ │ ├── ft_puterr.c │ │ ├── ft_putstr_fd.c │ │ ├── ft_strcmp.c │ │ ├── ft_strlen.c │ │ └── main.c │ └── ex02/ │ ├── Makefile │ ├── ft.h │ ├── ft_atoi.c │ ├── ft_putchar_fd.c │ ├── ft_puterr.c │ ├── ft_putstr_fd.c │ ├── ft_strcmp.c │ ├── ft_strlen.c │ ├── ft_strncpy.c │ ├── ft_tail.c │ └── main.c ├── c11/ │ ├── ex00/ │ │ └── ft_foreach.c │ ├── ex01/ │ │ └── ft_map.c │ ├── ex02/ │ │ └── ft_any.c │ ├── ex03/ │ │ └── ft_count_if.c │ ├── ex04/ │ │ └── ft_is_sort.c │ ├── ex05/ │ │ ├── Makefile │ │ ├── ft.h │ │ ├── ft_atoi.c │ │ ├── ft_op.c │ │ ├── ft_putchar.c │ │ ├── ft_putnbr.c │ │ ├── ft_putstr.c │ │ ├── ft_strlen.c │ │ └── main.c │ ├── ex06/ │ │ └── ft_sort_string_tab.c │ └── ex07/ │ └── ft_advanced_sort_string_tab.c ├── c12/ │ ├── Makefile │ ├── ex00/ │ │ ├── ft_create_elem.c │ │ └── ft_list.h │ ├── ex01/ │ │ ├── ft_list.h │ │ └── ft_list_push_front.c │ ├── ex02/ │ │ ├── ft_list.h │ │ └── ft_list_size.c │ ├── ex03/ │ │ ├── ft_list.h │ │ └── ft_list_last.c │ ├── ex04/ │ │ ├── ft_list.h │ │ └── ft_list_push_back.c │ ├── ex05/ │ │ ├── ft_list.h │ │ └── ft_list_push_strs.c │ ├── ex06/ │ │ ├── ft_list.h │ │ └── ft_list_clear.c │ ├── ex07/ │ │ ├── ft_list.h │ │ └── ft_list_at.c │ ├── ex08/ │ │ └── ft_list_reverse.c │ ├── ex09/ │ │ ├── ft_list.h │ │ └── ft_list_foreach.c │ ├── ex10/ │ │ ├── ft_list.h │ │ └── ft_list_foreach_if.c │ ├── ex11/ │ │ ├── ft_list.h │ │ └── ft_list_find.c │ ├── ex12/ │ │ ├── ft_list.h │ │ └── ft_list_remove_if.c │ ├── ex13/ │ │ ├── ft_list.h │ │ └── ft_list_merge.c │ ├── ex14/ │ │ ├── ft_list.h │ │ └── ft_list_sort.c │ ├── ex15/ │ │ ├── ft_list.h │ │ └── ft_list_reverse_fun.c │ ├── ex16/ │ │ ├── ft_list.h │ │ └── ft_sorted_list_insert.c │ ├── ex17/ │ │ ├── ft_list.h │ │ └── ft_sorted_list_merge.c │ ├── ft_list.h │ └── main.c ├── c13/ │ ├── Makefile │ ├── ex00/ │ │ ├── btree_create_node.c │ │ └── ft_btree.h │ ├── ex01/ │ │ ├── btree_apply_prefix.c │ │ └── ft_btree.h │ ├── ex02/ │ │ ├── btree_apply_infix.c │ │ └── ft_btree.h │ ├── ex03/ │ │ ├── btree_apply_suffix.c │ │ └── ft_btree.h │ ├── ex04/ │ │ ├── btree_insert_data.c │ │ └── ft_btree.h │ ├── ex05/ │ │ ├── btree_search_item.c │ │ └── ft_btree.h │ ├── ex06/ │ │ ├── btree_level_count.c │ │ └── ft_btree.h │ ├── ex07/ │ │ ├── btree_apply_by_level.c │ │ └── ft_btree.h │ ├── ft_btree.h │ └── main.c ├── other/ │ ├── binary.c │ ├── mkdirs.sh │ └── sorting.c ├── rush00/ │ └── ex00/ │ ├── ft_putchar.c │ ├── main.c │ ├── rush00.c │ ├── rush01.c │ ├── rush02.c │ ├── rush03.c │ └── rush04.c ├── rush01/ │ └── ex00/ │ ├── ft_backtrack.c │ ├── ft_check.c │ ├── ft_destroy_tab.c │ ├── ft_get_size.c │ ├── ft_init_tab.c │ ├── ft_print_tab.c │ ├── ft_putchar.c │ ├── ft_putstr.c │ ├── ft_rush.h │ └── main.c ├── rush02/ │ └── ex00/ │ ├── Makefile │ ├── includes/ │ │ ├── ft.h │ │ ├── ft_dict.h │ │ └── ft_list.h │ ├── numbers.dict │ ├── srcs/ │ │ ├── ft/ │ │ │ ├── ft_atol.c │ │ │ ├── ft_check_args.c │ │ │ ├── ft_file_load.c │ │ │ ├── ft_is_valid.c │ │ │ ├── ft_isdigit.c │ │ │ ├── ft_isprint.c │ │ │ ├── ft_isspace.c │ │ │ ├── ft_putchar.c │ │ │ ├── ft_putstr.c │ │ │ ├── ft_strlen.c │ │ │ └── ft_strncpy.c │ │ ├── ft_dict/ │ │ │ ├── ft_dict_clear.c │ │ │ ├── ft_dict_cmp.c │ │ │ ├── ft_dict_create.c │ │ │ ├── ft_dict_create_elem.c │ │ │ ├── ft_dict_in.c │ │ │ └── ft_print.c │ │ ├── ft_list/ │ │ │ ├── ft_create_elem.c │ │ │ ├── ft_list_clear.c │ │ │ ├── ft_list_find.c │ │ │ └── ft_sorted_list_insert.c │ │ └── main.c │ └── test.sh ├── shell00/ │ ├── ex00/ │ │ └── z │ ├── ex03/ │ │ └── klist.txt │ ├── ex04/ │ │ └── midLS │ ├── ex05/ │ │ └── git_commit.sh │ ├── ex06/ │ │ └── git_ignore.sh │ ├── ex07/ │ │ └── b │ ├── ex08/ │ │ └── clean │ └── ex09/ │ └── ft_magic └── shell01/ ├── ex01/ │ └── print_groups.sh ├── ex02/ │ └── find_sh.sh ├── ex03/ │ └── count_files.sh ├── ex04/ │ └── MAC.sh ├── ex05/ │ └── "\?$*'MaRViN'*$?\" ├── ex06/ │ └── skip.sh ├── ex07/ │ └── r_dwssap.sh └── ex08/ └── add_chelou.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Prerequisites *.d # Object files *.o *.ko *.obj *.elf # Linker output *.ilk *.map *.exp # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ *.su *.idb *.pdb # Kernel Module Compile Results *.mod* *.cmd .tmp_versions/ modules.order Module.symvers Mkfile.old dkms.conf ================================================ FILE: README.md ================================================ # Piscine 42 - Juillet 2019 Toutes les journées sont terminées, il manque un exercice sur le jour 10 de C Le rush02 est broken, RIP :skull: Certaines fonctions ne sont pas optimisées, notamment ft_strstr, mais elles fonctionnent :man_shrugging: Check [vimcake](https://github.com/ChuOkupai/vimcake) pour une config vim simple et efficace pour débuter ! Ce code n'est pas sous licence, le copier n'est cependant pas le meilleur moyen de progresser, à bon entendeur. ![alt text](https://i.redd.it/5iinczbed0yz.jpg) ================================================ FILE: bsq/Makefile ================================================ SRCS = ft_find_biggest_square.c \ ft_is_valid.c \ ft_file_load.c \ main.c OBJS = $(addprefix srcs/, ${SRCS:.c=.o}) SRC_HEADERS = ft.h HEADERS := $(addprefix includes/, ${SRC_HEADERS}) NAME = bsq CFLAGS = -Wall -Wextra -Werror -Ofast all: ${NAME} ${NAME}: ${OBJS} ${HEADERS} gcc ${CFLAGS} ${OBJS} -o $@ .c.o: ${HEADERS} gcc ${CFLAGS} -I./includes -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: bsq/auteur ================================================ asoursou:gdinet ================================================ FILE: bsq/gen.pl ================================================ #!/usr/bin/perl use warnings; use strict; die "program x y density" unless (scalar(@ARGV) == 3); my ($x, $y, $density) = @ARGV;print "$y.ox\n"; for (my $i = 0; $i < $y; $i++) { for (my $j = 0; $j < $x; $j++) { if (int(rand($y) * 2) < $density) { print "o"; } else { print "."; } } print "\n"; } ================================================ FILE: bsq/includes/ft.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/23 04:52:47 by asoursou #+# #+# */ /* Updated: 2019/07/24 21:03:04 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_H # define FT_H # define MAX_LINES 12000 # define BUFFER_SIZE 5800000 # define MIN(A, B) ((A < B) ? A : B) typedef struct s_point { int x; int y; } t_point; typedef struct s_map { char *content; char *matrix; char empty; char full; char obstacle; t_point size; } t_map; typedef struct s_square { t_point coords; int size; } t_square; char *ft_file_load(char *path); int ft_is_valid(t_map *m); void ft_find_biggest_square(t_map *m, t_square *s); #endif ================================================ FILE: bsq/srcs/ft_file_load.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_file_load.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gdinet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/23 09:14:34 by gdinet #+# #+# */ /* Updated: 2019/07/24 17:26:28 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "ft.h" char *ft_bufcpy(char *dest, char *src, int n) { char *d; d = dest; while (n--) *d++ = *src++; return (dest); } char *ft_file_read(int fd) { char buf[BUFFER_SIZE]; char *content; char *tmp; int len; int size; if (!(content = malloc(sizeof(char)))) return (NULL); *content = '\0'; size = 0; while ((len = read(fd, buf, BUFFER_SIZE)) > 0) { if (!(tmp = malloc((size + len + 1) * sizeof(char)))) break ; tmp = ft_bufcpy(tmp, content, size); free(content); ft_bufcpy(tmp + size, buf, len); content = tmp; size += len; content[size] = '\0'; } if (len) free(content); return ((len) ? NULL : content); } char *ft_file_load(char *path) { char *content; int fd; fd = (path) ? open(path, O_RDONLY) : STDIN_FILENO; if (fd < 0) return (NULL); content = ft_file_read(fd); if (fd != STDIN_FILENO) close(fd); return (content); } ================================================ FILE: bsq/srcs/ft_find_biggest_square.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_find_biggest_square.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/23 09:30:32 by asoursou #+# #+# */ /* Updated: 2019/07/24 21:00:55 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft.h" void ft_compute(t_map *m, t_square *s, int *t, t_point p) { int tmp; int u; u = 0; p.y = 0; while (++p.y <= m->size.y) { p.x = 0; while (++p.x <= m->size.x) { tmp = t[p.x]; if (m->matrix[p.x - 1 + (p.y - 1) * (1 + m->size.x)] == m->empty) { t[p.x] = MIN(MIN(u, t[p.x - 1]), t[p.x]) + 1; if (s->size < t[p.x]) { s->coords = p; s->size = t[p.x]; } } else t[p.x] = 0; u = tmp; } } } void ft_find_biggest_square(t_map *m, t_square *s) { t_point p; int tab[m->size.x + 1]; s->size = 0; p.x = 0; while (p.x <= m->size.x) tab[p.x++] = 0; ft_compute(m, s, tab, p); p.y = s->coords.y; s->coords.y -= s->size; s->coords.x -= s->size; while (p.y > s->coords.y) { p.y--; p.x = s->coords.x + s->size; while (p.x > s->coords.x) { p.x--; m->matrix[p.x + p.y * (1 + m->size.x)] = m->full; } } } ================================================ FILE: bsq/srcs/ft_is_valid.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_is_valid.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/24 09:25:05 by asoursou #+# #+# */ /* Updated: 2019/07/24 18:20:54 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" int ft_atoui(char *str, int *length) { long res; int i; res = 0; *length = 0; while (str[*length] >= '0' && str[*length] <= '9') (*length)++; i = 0; while (str[*length + i] && str[*length + i] != '\n') i++; if (i > 3) return (0); *length -= 3 - i; i = 0; while (i < *length) { res = res * 10 + str[i++] - '0'; if (res > INT_MAX) { res = 0; break ; } } return ((res > 16000) ? 0 : res); } int ft_check_line(t_map *m) { char *s; t_point p; s = m->matrix; p.x = -1; while (s[++p.x] != '\n') if (!s[p.x] || s[p.x] == m->full || (s[p.x] != m->empty && s[p.x] != m->obstacle)) return (0); m->size.x = p.x; p.y = 1; while (m->size.x == p.x++ && *(s += p.x)) { p.x = -1; while (s[++p.x] != '\n') if (!s[p.x] || s[p.x] == m->full || (s[p.x] != m->empty && s[p.x] != m->obstacle)) return (0); p.y++; } return (p.y == m->size.y); } int ft_is_valid(t_map *m) { int i; if ((m->size.y = ft_atoui(m->content, &i)) <= 0) return (0); if (m->content[i] != '\0' && m->content[i] != '\n') m->empty = m->content[i++]; else return (0); if (m->content[i] != '\0' && m->content[i] != '\n') m->obstacle = m->content[i++]; else return (0); if (m->content[i] != '\0' && m->content[i] != '\n') m->full = m->content[i++]; else return (0); if (m->content[i] != '\n' || m->empty == m->full || m->empty == m->obstacle || m->full == m->obstacle) return (0); m->matrix = m->content + i + 1; return (ft_check_line(m)); } ================================================ FILE: bsq/srcs/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:32:28 by asoursou #+# #+# */ /* Updated: 2019/07/24 18:15:04 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include "ft.h" static void ft_bsq(char *path) { t_map map; t_square square; int y; if (!(map.content = ft_file_load(path)) || !ft_is_valid(&map)) write(STDERR_FILENO, "map error\n", 10); else { ft_find_biggest_square(&map, &square); map.size.x++; y = 0; while (y < map.size.y) write(STDOUT_FILENO, map.matrix + map.size.x * y++, map.size.x); } free(map.content); } int main(int argc, char **argv) { char c; int i; if (argc < 2) { ft_bsq(NULL); return (0); } c = '\n'; i = 0; while (++i < argc) { if (i > 1) write(STDOUT_FILENO, &c, 1); ft_bsq(argv[i]); } return (0); } ================================================ FILE: c00/ex00/ft_putchar.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:19:29 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:28:36 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } ================================================ FILE: c00/ex01/ft_print_alphabet.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_alphabet.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:26:51 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:30:59 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_print_alphabet(void) { write(1, "abcdefghijklmnopqrstuvwxyz", 26); } ================================================ FILE: c00/ex02/ft_print_reverse_alphabet.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_reverse_alphabet.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:45:28 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:30:59 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_print_reverse_alphabet(void) { write(1, "zyxwvutsrqponmlkjihgfedcba", 26); } ================================================ FILE: c00/ex03/ft_print_numbers.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_numbers.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:44:10 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:32:39 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_print_numbers(void) { write(1, "0123456789", 10); } ================================================ FILE: c00/ex04/ft_is_negative.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_is_negative.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:47:18 by asoursou #+# #+# */ /* Updated: 2019/07/02 21:52:13 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_is_negative(int n) { ft_putchar((n < 0) ? 'N' : 'P'); } ================================================ FILE: c00/ex05/ft_print_comb.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_comb.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:56:52 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:36:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_print_comb(void) { char t[5]; *t = '0'; t[1] = '1'; t[2] = '2'; t[3] = ','; t[4] = ' '; while (*t < '8') { write(1, t, (*t != '7') ? 5 : 3); if (++t[2] > '9') { if (++t[1] > '8') t[1] = ++(*t) + 1; t[2] = t[1] + 1; } } } ================================================ FILE: c00/ex06/ft_print_comb2.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_comb2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/02 12:29:57 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:43:21 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_print_comb2(void) { char a; char b; a = 0; b = 1; while (a < 99) { ft_putchar(a / 10 + '0'); ft_putchar(a % 10 + '0'); ft_putchar(' '); ft_putchar(b / 10 + '0'); ft_putchar(b % 10 + '0'); if (a < 98) write(1, ", ", 2); if (++b > 99) b = ++a + 1; } } ================================================ FILE: c00/ex07/ft_putnbr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putnbr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/02 13:02:20 by asoursou #+# #+# */ /* Updated: 2019/07/02 16:38:06 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_putnbr(int nb) { unsigned int n; if (nb < 0) { ft_putchar('-'); n = -nb; } else n = nb; if (n > 9) { ft_putnbr(n / 10); n %= 10; } ft_putchar(n + '0'); } ================================================ FILE: c00/ex08/ft_print_combn.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_combn.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/02 17:39:52 by asoursou #+# #+# */ /* Updated: 2019/07/02 21:49:26 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_print_combn(int n) { char t[11]; int i; if (n < 1 || n > 9) return ; *t = '0'; i = 0; while (++i < n) t[i] = t[i - 1] + 1; t[n] = ','; t[n + 1] = ' '; while (*t <= 58 - n) { write(1, t, n + ((*t != 58 - n) ? 2 : 0)); i = n; while (i--) if (++t[i] <= 58 - n + i) break ; while (++i > 0 && i < n) t[i] = t[i - 1] + 1; } } ================================================ FILE: c01/ex00/ft_ft.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_ft.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 02:49:17 by asoursou #+# #+# */ /* Updated: 2019/07/03 02:50:02 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_ft(int *nbr) { *nbr = 42; } ================================================ FILE: c01/ex01/ft_ultimate_ft.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_ultimate_ft.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 02:50:59 by asoursou #+# #+# */ /* Updated: 2019/07/03 02:52:17 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_ultimate_ft(int *********nbr) { *********nbr = 42; } ================================================ FILE: c01/ex02/ft_swap.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_swap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 02:53:08 by asoursou #+# #+# */ /* Updated: 2019/07/03 02:54:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; } ================================================ FILE: c01/ex03/ft_div_mod.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_div_mod.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 02:54:28 by asoursou #+# #+# */ /* Updated: 2019/07/03 02:56:30 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_div_mod(int a, int b, int *div, int *mod) { *div = a / b; *mod = a % b; } ================================================ FILE: c01/ex04/ft_ultimate_div_mod.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_ultimate_div_mod.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 02:57:55 by asoursou #+# #+# */ /* Updated: 2019/07/03 15:19:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_ultimate_div_mod(int *a, int *b) { int c; c = *a; *a /= *b; *b = c % *b; } ================================================ FILE: c01/ex05/ft_putstr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:00:11 by asoursou #+# #+# */ /* Updated: 2019/07/03 03:10:15 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } void ft_putstr(char *str) { write(1, str, ft_strlen(str)); } ================================================ FILE: c01/ex06/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/03 15:18:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: c01/ex07/ft_rev_int_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_rev_int_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:13:10 by asoursou #+# #+# */ /* Updated: 2019/07/03 03:26:16 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; } void ft_rev_int_tab(int *tab, int size) { int left; if (size < 2) return ; left = 0; while (left < --size) ft_swap(&tab[left++], &tab[size]); } ================================================ FILE: c01/ex08/ft_sort_int_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sort_int_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:27:57 by asoursou #+# #+# */ /* Updated: 2019/07/03 04:33:21 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; } void ft_sort_int_tab(int *tab, int size) { int pivot; int i; int j; if (size < 2) return ; pivot = tab[--size]; i = 0; j = -1; while (++j < size) if (tab[j] < pivot) ft_swap(&tab[i++], &tab[j]); if (tab[i] > tab[size]) ft_swap(&tab[i], &tab[size]); ft_sort_int_tab(tab, i); ft_sort_int_tab(tab + i + 1, size - i); } ================================================ FILE: c02/ex00/ft_strcpy.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 04:58:09 by asoursou #+# #+# */ /* Updated: 2019/07/03 05:01:42 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strcpy(char *dest, char *src) { int i; i = -1; while (src[++i]) dest[i] = src[i]; dest[i] = '\0'; return (dest); } ================================================ FILE: c02/ex01/ft_strncpy.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 22:19:44 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:19:46 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strncpy(char *dest, char *src, unsigned int n) { unsigned int i; i = -1; while (++i < n && src[i]) dest[i] = src[i]; while (i < n) dest[i++] = '\0'; return (dest); } ================================================ FILE: c02/ex02/ft_str_is_alpha.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_str_is_alpha.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 13:56:21 by asoursou #+# #+# */ /* Updated: 2019/07/03 16:28:24 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_str_is_alpha(char *str) { while (*str) { if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z'))) return (0); str++; } return (1); } ================================================ FILE: c02/ex03/ft_str_is_numeric.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_str_is_numeric.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 16:26:20 by asoursou #+# #+# */ /* Updated: 2019/07/03 17:44:41 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_str_is_numeric(char *str) { while (*str) { if (*str < '0' || *str > '9') return (0); str++; } return (1); } ================================================ FILE: c02/ex04/ft_str_is_lowercase.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_str_is_lowercase.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 16:27:44 by asoursou #+# #+# */ /* Updated: 2019/07/03 19:48:48 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_str_is_lowercase(char *str) { while (*str) { if (*str < 'a' || *str > 'z') return (0); str++; } return (1); } ================================================ FILE: c02/ex05/ft_str_is_uppercase.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_str_is_uppercase.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 17:48:28 by asoursou #+# #+# */ /* Updated: 2019/07/03 19:35:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_str_is_uppercase(char *str) { while (*str) { if (*str < 'A' || *str > 'Z') return (0); str++; } return (1); } ================================================ FILE: c02/ex06/ft_str_is_printable.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_str_is_printable.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 18:31:22 by asoursou #+# #+# */ /* Updated: 2019/07/03 18:42:20 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_str_is_printable(char *str) { while (*str) { if (*str < ' ' || *str == 127) return (0); str++; } return (1); } ================================================ FILE: c02/ex07/ft_strupcase.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strupcase.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 18:58:53 by asoursou #+# #+# */ /* Updated: 2019/07/03 19:39:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strupcase(char *str) { char *s; s = str; while (*s) { if (*s >= 'a' && *s <= 'z') *s -= 32; s++; } return (str); } ================================================ FILE: c02/ex08/ft_strlowcase.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlowcase.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 19:39:28 by asoursou #+# #+# */ /* Updated: 2019/07/03 19:42:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strlowcase(char *str) { char *s; s = str; while (*s) { if (*s >= 'A' && *s <= 'Z') *s += 32; s++; } return (str); } ================================================ FILE: c02/ex09/ft_strcapitalize.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcapitalize.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 19:42:24 by asoursou #+# #+# */ /* Updated: 2019/07/05 04:12:21 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isdigit(char c) { return (c >= '0' && c <= '9'); } int ft_islower(char c) { return (c >= 'a' && c <= 'z'); } int ft_isupper(char c) { return (c >= 'A' && c <= 'Z'); } char *ft_strcapitalize(char *str) { char *s; s = str; while (*s) { if (ft_isdigit(*s) || ft_islower(*s) || ft_isupper(*s)) { if (ft_isdigit(*s)) while (ft_isdigit(s[1])) s++; else if (ft_islower(*s)) *s -= 32; while (ft_islower(*(++s)) || ft_isupper(*s)) if (ft_isupper(*s)) *s += 32; } else s++; } return (str); } ================================================ FILE: c02/ex10/ft_strlcpy.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlcpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 21:11:14 by asoursou #+# #+# */ /* Updated: 2019/07/05 07:02:17 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } unsigned int ft_strlcpy(char *dest, char *src, unsigned int size) { unsigned int i; unsigned int j; i = ft_strlen(src); if (i + 1 < size) { j = -1; while (++j < i + 1) dest[j] = src[j]; } else if (size) { j = -1; while (++j < size - 1) dest[j] = src[j]; dest[j] = '\0'; } return (i); } ================================================ FILE: c02/ex11/ft_putstr_non_printable.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr_non_printable.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 22:18:10 by asoursou #+# #+# */ /* Updated: 2019/07/05 15:05:11 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_puthex(unsigned char c) { char *base; base = "0123456789abcdef"; ft_putchar(base[c / 16]); ft_putchar(base[c % 16]); } void ft_putstr_non_printable(char *str) { while (*str) { if (*str < ' ' || *str == 127) { ft_putchar('\\'); ft_puthex(*str); } else ft_putchar(*str); str++; } } ================================================ FILE: c02/ex12/ft_print_memory.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_memory.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 23:22:04 by asoursou #+# #+# */ /* Updated: 2019/07/05 16:39:37 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_puthex(unsigned char c) { char *base; base = "0123456789abcdef"; ft_putchar(base[c / 16]); ft_putchar(base[c % 16]); } void ft_print_data(char *s, unsigned int size) { unsigned int i; i = -1; while (++i < size) { if (!(i % 2)) ft_putchar(' '); ft_puthex(s[i]); } while (i < 16) write(1, " ", (i++ % 2) ? 2 : 3); ft_putchar(' '); i = -1; while (++i < size) ft_putchar((s[i] < ' ' || s[i] == 127) ? '.' : s[i]); } void *ft_print_memory(void *addr, unsigned int size) { unsigned int i; int j; i = 0; while (i < size) { ft_putchar('0'); j = 56; while ((j -= 8) >= 0) ft_puthex((unsigned long int)(addr + i) >> j & 0xff); ft_putchar(':'); ft_print_data(addr + i, (size - i < 16) ? size - i : 16); ft_putchar('\n'); i += 16; } return (addr); } ================================================ FILE: c03/ex00/ft_strcmp.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 01:25:21 by asoursou #+# #+# */ /* Updated: 2019/07/04 01:37:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strcmp(char *s1, char *s2) { while (*s1 && *s1 == *s2) { s1++; s2++; } return (*s1 - *s2); } ================================================ FILE: c03/ex01/ft_strncmp.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 01:48:20 by asoursou #+# #+# */ /* Updated: 2019/07/04 01:48:22 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strncmp(char *s1, char *s2, unsigned int n) { while (n && *s1 && *s1 == *s2) { s1++; s2++; n--; } return ((n) ? *s1 - *s2 : 0); } ================================================ FILE: c03/ex02/ft_strcat.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcat.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 01:48:44 by asoursou #+# #+# */ /* Updated: 2019/07/04 01:55:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strcat(char *dest, char *src) { char *d; d = dest; while (*d) d++; while (*src) *d++ = *src++; *d = '\0'; return (dest); } ================================================ FILE: c03/ex03/ft_strncat.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncat.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 18:34:45 by asoursou #+# #+# */ /* Updated: 2019/07/04 18:45:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strncat(char *dest, char *src, unsigned int nb) { char *d; d = dest; while (*d) d++; while (nb-- && *src) *d++ = *src++; *d = '\0'; return (dest); } ================================================ FILE: c03/ex04/ft_strstr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 18:45:38 by asoursou #+# #+# */ /* Updated: 2019/07/05 06:32:38 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strstr(char *str, char *to_find) { int i; if (!*to_find) return (str); while (*str) { if (*str == *to_find) { i = 1; while (to_find[i] && str[i] == to_find[i]) i++; if (!to_find[i]) return (str); } str++; } return (0); } ================================================ FILE: c03/ex05/ft_strlcat.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlcat.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 21:49:16 by asoursou #+# #+# */ /* Updated: 2019/07/05 06:31:28 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } unsigned int ft_strlcat(char *dest, char *src, unsigned int size) { unsigned int i; unsigned int j; i = -1; while (++i < size && *dest) dest++; if (i == size) return (i + (unsigned int)ft_strlen(src)); j = -1; while (src[++j]) if (j < size - i - 1) *dest++ = src[j]; *dest = '\0'; return (i + j); } ================================================ FILE: c04/ex00/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:30:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: c04/ex01/ft_putstr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:00:11 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:40:51 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } void ft_putstr(char *str) { write(1, str, ft_strlen(str)); } ================================================ FILE: c04/ex02/ft_putnbr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putnbr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/02 13:02:20 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:40:51 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_putnbr(int nb) { unsigned int n; if (nb < 0) { ft_putchar('-'); n = -nb; } else n = nb; if (n > 9) { ft_putnbr(n / 10); n %= 10; } ft_putchar(n + '0'); } ================================================ FILE: c04/ex03/ft_atoi.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 06:20:50 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:35:23 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_atoi(char *str) { int n; int negative; while ((*str >= 9 && *str <= 13) || *str == ' ') str++; negative = 0; while (*str == '-' || *str == '+') if (*str++ == '-') negative = 1 - negative; n = 0; while (*str >= '0' && *str <= '9') n = n * 10 + *str++ - '0'; if (negative) n *= -1; return (n); } ================================================ FILE: c04/ex04/ft_putnbr_base.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putnbr_base.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 06:45:07 by asoursou #+# #+# */ /* Updated: 2019/07/07 06:18:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } int ft_in_base(char c, char *base) { while (*base) if (c == *base++) return (1); return (0); } void ft_print(unsigned int n, char *base, unsigned int size) { if (n > size - 1) { ft_print(n / size, base, size); n %= size; } ft_putchar(base[n]); } void ft_putnbr_base(int nbr, char *base) { int size; size = -1; while (base[++size]) if (base[size] == '+' || base[size] == '-' || base[size] == ' ' || ft_in_base(base[size], base + size + 1) || (base[size] >= 9 && base[size] <= 13)) return ; if (size < 2) return ; if (nbr < 0) { ft_putchar('-'); ft_print(-nbr, base, size); } else ft_print(nbr, base, size); } ================================================ FILE: c04/ex05/ft_atoi_base.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi_base.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 20:27:50 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:41:48 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_in_base(char c, char *base) { int i; i = -1; while (base[++i]) if (c == base[i]) return (i); return (-1); } int ft_baselen(char *base) { int size; size = -1; while (base[++size]) if (base[size] == '+' || base[size] == '-' || base[size] == ' ' || ft_in_base(base[size], base + size + 1) >= 0 || (base[size] >= 9 && base[size] <= 13)) return (0); return (size); } int ft_atoi_base(char *str, char *base) { int i; int n; int negative; int size; if ((size = ft_baselen(base)) < 2) return (0); while ((*str >= 9 && *str <= 13) || *str == ' ') str++; negative = 0; while (*str == '-' || *str == '+') if (*str++ == '-') negative = 1 - negative; n = 0; while ((i = ft_in_base(*str, base)) >= 0) { n = n * size + i; str++; } if (negative) n *= -1; return (n); } ================================================ FILE: c05/ex00/ft_iterative_factorial.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_iterative_factorial.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 08:16:02 by asoursou #+# #+# */ /* Updated: 2019/07/08 04:31:35 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_iterative_factorial(int nb) { int n; if (nb < 1) return (!nb); n = 1; while (nb) n *= nb--; return (n); } ================================================ FILE: c05/ex01/ft_recursive_factorial.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_recursive_factorial.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 08:22:08 by asoursou #+# #+# */ /* Updated: 2019/07/08 04:35:45 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_recursive_factorial(int nb) { if (nb < 1) return (!nb); return (nb * ft_recursive_factorial(nb - 1)); } ================================================ FILE: c05/ex02/ft_iterative_power.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_iterative_power.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 08:25:43 by asoursou #+# #+# */ /* Updated: 2019/07/08 07:01:52 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_iterative_power(int nb, int power) { int n; if (power < 1) return (!power); n = nb; while (--power) n *= nb; return (n); } ================================================ FILE: c05/ex03/ft_recursive_power.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_recursive_power.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 08:31:46 by asoursou #+# #+# */ /* Updated: 2019/07/08 05:46:12 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_recursive_power(int nb, int power) { if (power < 1) return (!power); return (nb * ft_recursive_power(nb, power - 1)); } ================================================ FILE: c05/ex04/ft_fibonacci.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_fibonacci.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 09:02:55 by asoursou #+# #+# */ /* Updated: 2019/07/08 05:51:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_fibonacci(int index) { if (index < 0) return (-1); if (index < 2) return (index); return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2)); } ================================================ FILE: c05/ex05/ft_sqrt.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sqrt.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 09:06:22 by asoursou #+# #+# */ /* Updated: 2019/07/08 09:16:16 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_sqrt(int nb) { unsigned int i; if (nb < 1) return (0); i = 1; while (i * i < (unsigned int)nb) i++; return ((i * i == (unsigned int)nb) ? i : 0); } ================================================ FILE: c05/ex06/ft_is_prime.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_is_prime.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 09:35:19 by asoursou #+# #+# */ /* Updated: 2019/07/08 09:29:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_is_prime(int nb) { unsigned int i; if (nb < 3 || !(nb % 2)) return (nb == 2); i = 3; while (i * i <= (unsigned int)nb) { if (!(nb % i)) return (0); i += 2; } return (1); } ================================================ FILE: c05/ex07/ft_find_next_prime.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_find_next_prime.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/08 03:52:29 by asoursou #+# #+# */ /* Updated: 2019/07/08 09:22:50 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_find_next_prime(int nb) { unsigned int i; if (nb < 3) return (2); if (!(nb % 2)) nb++; i = 3; while (i * i <= (unsigned int)nb) { if (!(nb % i)) { nb += 2; i = 1; } i += 2; } return (nb); } ================================================ FILE: c05/ex08/ft_ten_queens_puzzle.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_ten_queens_puzzle.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/25 12:22:47 by asoursou #+# #+# */ /* Updated: 2019/07/25 13:30:01 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } int ft_abs(int n) { return (n < 0) ? -n : n; } void ft_solve(char *tab, int x, int *max) { int i; int j; if (x == 10) { x = 0; while (x < 10) ft_putchar(tab[x++] + '0'); ft_putchar('\n'); (*max)++; return ; } i = -1; while (++i < 10) { j = 0; while (j < x && i != tab[j] && ft_abs(tab[j] - i) != x - j) j++; if (j >= x) { tab[x] = i; ft_solve(tab, x + 1, max); } } } int ft_ten_queens_puzzle(void) { char tab[10]; int max; max = 0; ft_solve(tab, 0, &max); return (max); } ================================================ FILE: c06/ex00/ft_print_program_name.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_program_name.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/09 03:20:37 by asoursou #+# #+# */ /* Updated: 2019/07/09 03:20:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_putstr(char *str) { while (*str) ft_putchar(*str++); } int main(int argc, char **argv) { if (argc) { ft_putstr(argv[0]); ft_putchar('\n'); } return (0); } ================================================ FILE: c06/ex01/ft_print_params.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_params.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/08 07:56:58 by asoursou #+# #+# */ /* Updated: 2019/07/08 23:45:06 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_putstr(char *str) { while (*str) ft_putchar(*str++); } int main(int argc, char **argv) { int i; i = 1; while (i < argc) { ft_putstr(argv[i++]); ft_putchar('\n'); } return (0); } ================================================ FILE: c06/ex02/ft_rev_params.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_rev_params.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/08 21:52:57 by asoursou #+# #+# */ /* Updated: 2019/07/08 23:45:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } void ft_putstr(char *str) { while (*str) ft_putchar(*str++); } int main(int argc, char **argv) { while (argc > 1) { ft_putstr(argv[--argc]); ft_putchar('\n'); } return (0); } ================================================ FILE: c06/ex03/ft_sort_params.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sort_params.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/08 21:58:42 by asoursou #+# #+# */ /* Updated: 2019/07/09 00:09:19 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } int ft_strcmp(char *s1, char *s2) { while (*s1 && *s1 == *s2) { s1++; s2++; } return (*s1 - *s2); } void ft_strswap(char **a, char **b) { char *c; c = *a; *a = *b; *b = c; } void ft_sort_str_tab(char **tab, int size) { char *pivot; int i; int j; if (size < 2) return ; pivot = tab[--size]; i = 0; j = -1; while (++j < size) if (ft_strcmp(tab[j], pivot) < 0) ft_strswap(&tab[i++], &tab[j]); if (ft_strcmp(tab[i], tab[size]) > 0) ft_strswap(&tab[i], &tab[size]); ft_sort_str_tab(tab, i); ft_sort_str_tab(tab + i + 1, size - i); } int main(int argc, char **argv) { int i; ft_sort_str_tab(argv + 1, argc - 1); i = 0; while (++i < argc) { while (*argv[i]) ft_putchar(*argv[i]++); ft_putchar('\n'); } return (0); } ================================================ FILE: c07/ex00/ft_strdup.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strdup.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/09 02:30:44 by asoursou #+# #+# */ /* Updated: 2019/07/09 21:35:58 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } char *ft_strcpy(char *dest, char *src) { int i; i = -1; while (src[++i]) dest[i] = src[i]; dest[i] = '\0'; return (dest); } char *ft_strdup(char *src) { char *dest; dest = malloc((ft_strlen(src) + 1) * sizeof(char)); if (!dest) return (NULL); return (ft_strcpy(dest, src)); } ================================================ FILE: c07/ex01/ft_range.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_range.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/09 03:30:38 by asoursou #+# #+# */ /* Updated: 2019/07/09 21:36:52 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int *ft_range(int min, int max) { int *t; int i; if (min >= max) return (NULL); max -= min; t = malloc(max * sizeof(int)); if (!t) return (NULL); i = -1; while (++i < max) t[i] = min + i; return (t); } ================================================ FILE: c07/ex02/ft_ultimate_range.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_ultimate_range.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/09 03:57:58 by asoursou #+# #+# */ /* Updated: 2019/07/10 05:14:42 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_ultimate_range(int **range, int min, int max) { int i; if (min >= max) { *range = NULL; return (0); } max -= min; *range = malloc(max * sizeof(int)); if (!*range) return (-1); i = -1; while (++i < max) (*range)[i] = min + i; return (max); } ================================================ FILE: c07/ex03/ft_strjoin.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strjoin.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/09 21:35:31 by asoursou #+# #+# */ /* Updated: 2019/07/10 06:01:55 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } char *ft_strcpy(char *dest, char *src) { int i; i = -1; while (src[++i]) dest[i] = src[i]; dest[i] = '\0'; return (dest); } char *ft_strjoin(int size, char **strs, char *sep) { char *dest; int i; int j; i = 0; j = 0; while (i < size) j += ft_strlen(strs[i++]); if (size > 0) j += (size - 1) * ft_strlen(sep); dest = malloc((j + 1) * sizeof(char)); if (!dest) return (NULL); i = 0; j = 0; while (i < size) { ft_strcpy(dest + j, strs[i]); j += ft_strlen(strs[i]); if (++i < size) j += dest + j + ft_strlen(sep) - ft_strcpy(dest + j, sep); } dest[j] = '\0'; return (dest); } ================================================ FILE: c07/ex04/ft_convert_base.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_convert_base.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/10 05:20:33 by asoursou #+# #+# */ /* Updated: 2019/07/11 02:13:52 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_in_base(char c, char *base) { int i; i = -1; while (base[++i]) if (c == base[i]) return (i); return (-1); } int ft_checkbase(char *base) { int i; i = -1; while (base[++i]) if (base[i] == '+' || base[i] == '-' || base[i] == ' ' || ft_in_base(base[i], base + i + 1) >= 0 || (base[i] >= 9 && base[i] <= 13)) return (0); return ((i < 2) ? 0 : i); } int ft_atoi_base(char *str, char *base, int size) { int i; int n; int negative; while ((*str >= 9 && *str <= 13) || *str == ' ') str++; negative = 0; while (*str == '-' || *str == '+') if (*str++ == '-') negative = 1 - negative; n = 0; while ((i = ft_in_base(*str++, base)) >= 0) n = n * size + i; if (negative) n *= -1; return (n); } int ft_nbrlen(unsigned int n, unsigned int base_size) { if (n < base_size) return (1); return (1 + ft_nbrlen(n / base_size, base_size)); } char *ft_convert_base(char *nbr, char *base_from, char *base_to) { char *dest; unsigned int nb; int size; int i; int n; n = ft_checkbase(base_from); if (!(n && (size = ft_checkbase(base_to)))) return (NULL); n = ft_atoi_base(nbr, base_from, n); nb = (n < 0) ? -n : n; i = ft_nbrlen(nb, size) + ((n < 0) ? 1 : 0); if (!(dest = malloc((i + 1) * sizeof(char)))) return (NULL); dest[i] = '\0'; while (i--) { dest[i] = base_to[nb % size]; nb /= size; } if (n < 0) dest[0] = '-'; return (dest); } ================================================ FILE: c07/ex04/ft_convert_base2.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_convert_base2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/10 06:20:53 by asoursou #+# #+# */ /* Updated: 2019/07/10 09:56:54 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_useless(void) { return ; } ================================================ FILE: c07/ex05/ft_split.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_split.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/10 05:33:05 by asoursou #+# #+# */ /* Updated: 2019/07/12 10:41:51 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_is_separator(char *str, char *charset) { while (*charset) if (*str == *charset++) return (1); return (0); } int ft_wordlen(char *str, char *charset) { int i; i = 0; while (str[i] && !ft_is_separator(str + i, charset)) i++; return (i); } int ft_wordcount(char *str, char *charset) { int i; int w; w = 0; while (*str) { while (*str && ft_is_separator(str, charset)) str++; i = ft_wordlen(str, charset); str += i; if (i) w++; } return (w); } char *ft_wordcpy(char *src, int n) { char *dest; if (!(dest = malloc((n + 1) * sizeof(char)))) return (NULL); dest[n] = '\0'; while (n--) dest[n] = src[n]; return (dest); } char **ft_split(char *str, char *charset) { char **t; int size; int i; int n; size = ft_wordcount(str, charset); if (!(t = malloc((size + 1) * sizeof(char*)))) return (NULL); i = -1; while (++i < size) { while (*str && ft_is_separator(str, charset)) str++; n = ft_wordlen(str, charset); if (!(t[i] = ft_wordcpy(str, n))) return (NULL); str += n; } t[size] = 0; return (t); } ================================================ FILE: c08/ex00/ft.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 08:21:45 by asoursou #+# #+# */ /* Updated: 2019/07/11 10:24:47 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_H # define FT_H void ft_putchar(char c); void ft_swap(int *a, int *b); void ft_putstr(char *str); int ft_strlen(char *str); int ft_strcmp(char *s1, char *s2); #endif ================================================ FILE: c08/ex01/ft_boolean.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_boolean.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 10:31:29 by asoursou #+# #+# */ /* Updated: 2019/07/11 11:23:59 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BOOLEAN_H # define FT_BOOLEAN_H # include typedef char t_bool; # define FALSE 0 # define TRUE 1 # define SUCCESS 0 # define EVEN_MSG "I have an even number of arguments.\n" # define ODD_MSG "I have an odd number of arguments.\n" # define EVEN(X) ((X % 2) ? 0 : 1) #endif ================================================ FILE: c08/ex02/ft_abs.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_abs.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 11:12:59 by asoursou #+# #+# */ /* Updated: 2019/07/11 11:15:09 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_ABS_H # define FT_ABS_H # define ABS(Value) ((Value < 0) ? -Value : Value) #endif ================================================ FILE: c08/ex03/ft_point.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_point.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 11:16:08 by asoursou #+# #+# */ /* Updated: 2019/07/11 16:05:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_POINT_H # define FT_POINT_H typedef struct s_point { int x; int y; } t_point; #endif ================================================ FILE: c08/ex04/ft_strs_to_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strs_to_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 11:52:29 by asoursou #+# #+# */ /* Updated: 2019/07/12 11:12:38 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_stock_str.h" int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } char *ft_strdup(char *src) { char *dest; int i; dest = malloc((ft_strlen(src) + 1) * sizeof(char)); if (!dest) return (NULL); i = -1; while (src[++i]) dest[i] = src[i]; dest[i] = '\0'; return (dest); } struct s_stock_str *ft_strs_to_tab(int ac, char **av) { t_stock_str *t; int i; if (ac < 0) ac = 0; if (!(t = malloc((ac + 1) * sizeof(t_stock_str)))) return (NULL); i = -1; while (++i < ac) { t[i].size = ft_strlen(av[i]); t[i].str = av[i]; t[i].copy = ft_strdup(av[i]); } t[i].str = 0; return (t); } ================================================ FILE: c08/ex05/ft_show_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_show_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 15:24:50 by asoursou #+# #+# */ /* Updated: 2019/07/11 15:46:18 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_stock_str.h" void ft_putchar(char c) { write(1, &c, 1); } void ft_puts(char *str) { while (*str) ft_putchar(*str++); ft_putchar('\n'); } void ft_putnbr(int nb) { unsigned int n; if (nb < 0) { ft_putchar('-'); n = -nb; } else n = nb; if (n > 9) { ft_putnbr(n / 10); n %= 10; } ft_putchar(n + '0'); } void ft_show_tab(struct s_stock_str *par) { if (!par) return ; while (par->str) { ft_puts(par->str); ft_putnbr(par->size); ft_putchar('\n'); ft_puts(par->copy); par++; } } ================================================ FILE: c09/ex00/ft_putchar.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:19:29 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:28:36 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } ================================================ FILE: c09/ex00/ft_putstr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:00:11 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:40:51 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } void ft_putstr(char *str) { write(1, str, ft_strlen(str)); } ================================================ FILE: c09/ex00/ft_strcmp.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 01:25:21 by asoursou #+# #+# */ /* Updated: 2019/07/04 01:37:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strcmp(char *s1, char *s2) { while (*s1 && *s1 == *s2) { s1++; s2++; } return (*s1 - *s2); } ================================================ FILE: c09/ex00/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:30:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: c09/ex00/ft_swap.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_swap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 02:53:08 by asoursou #+# #+# */ /* Updated: 2019/07/03 02:54:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; } ================================================ FILE: c09/ex00/libft_creator.sh ================================================ #!/bin/sh gcc -Wall -Wextra -Werror -c *.c ar -rcs libft.a *.o ================================================ FILE: c09/ex01/Makefile ================================================ SRCS = ft_putchar.c ft_swap.c ft_putstr.c ft_strlen.c ft_strcmp.c OBJS = $(addprefix srcs/, ${SRCS:.c=.o}) NAME = libft.a .c.o: gcc -Wall -Wextra -Werror -c -I./includes $< -o ${<:.c=.o} ${NAME}: ${OBJS} ar -rcs $@ $^ all: ${NAME} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: c09/ex02/ft_split.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_split.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/10 05:33:05 by asoursou #+# #+# */ /* Updated: 2019/07/12 10:41:51 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int ft_is_separator(char *str, char *charset) { while (*charset) if (*str == *charset++) return (1); return (0); } int ft_wordlen(char *str, char *charset) { int i; i = 0; while (str[i] && !ft_is_separator(str + i, charset)) i++; return (i); } int ft_wordcount(char *str, char *charset) { int i; int w; w = 0; while (*str) { while (*str && ft_is_separator(str, charset)) str++; i = ft_wordlen(str, charset); str += i; if (i) w++; } return (w); } char *ft_wordcpy(char *src, int n) { char *dest; if (!(dest = malloc((n + 1) * sizeof(char)))) return (NULL); dest[n] = '\0'; while (n--) dest[n] = src[n]; return (dest); } char **ft_split(char *str, char *charset) { char **t; int size; int i; int n; size = ft_wordcount(str, charset); if (!(t = malloc((size + 1) * sizeof(char*)))) return (NULL); i = -1; while (++i < size) { while (*str && ft_is_separator(str, charset)) str++; n = ft_wordlen(str, charset); if (!(t[i] = ft_wordcpy(str, n))) return (NULL); str += n; } t[size] = 0; return (t); } ================================================ FILE: c10/ex00/Makefile ================================================ SRCS = ft_display_file.c \ ft_putstr_fd.c \ ft_strlen.c \ main.c OBJS = ${SRCS:.c=.o} NAME = ft_display_file CFLAGS = -Wall -Wextra -Werror all: ${NAME} ${NAME}: ${OBJS} gcc ${CFLAGS} $^ -o $@ .c.o: gcc ${CFLAGS} -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: c10/ex00/ft.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 22:32:41 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:33:37 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_H # define FT_H int ft_display_file(char *path); void ft_putstr_fd(char *str, int fd); int ft_strlen(char *str); #endif ================================================ FILE: c10/ex00/ft_display_file.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_display_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/14 22:17:46 by asoursou #+# #+# */ /* Updated: 2019/07/15 16:45:01 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include int ft_display_file(char *path) { char buf[2048]; int fd; int len; if ((fd = open(path, O_RDONLY)) < 0) return (-1); while ((len = read(fd, buf, 2048)) > 0) write(1, buf, len); close(fd); return ((len) ? -1 : 0); } ================================================ FILE: c10/ex00/ft_putstr_fd.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr_fd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:42:27 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:34:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_putstr_fd(char *str, int fd) { write(fd, str, ft_strlen(str)); } ================================================ FILE: c10/ex00/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/03 15:18:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: c10/ex00/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:32:28 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:34:16 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" int main(int argc, char **argv) { if (argc < 2) ft_putstr_fd("File name missing.\n", STDERR_FILENO); else if (argc > 2) ft_putstr_fd("Too many arguments.\n", STDERR_FILENO); else if (ft_display_file(argv[1]) < 0) ft_putstr_fd("Cannot read file.\n", STDERR_FILENO); return (0); } ================================================ FILE: c10/ex01/Makefile ================================================ SRCS = ft_display_file.c \ ft_putchar_fd.c \ ft_puterr.c \ ft_putstr_fd.c \ ft_strcmp.c \ ft_strlen.c \ main.c OBJS = ${SRCS:.c=.o} NAME = ft_cat CFLAGS = -Wall -Wextra -Werror all: ${NAME} ${NAME}: ${OBJS} gcc ${CFLAGS} $^ -o $@ .c.o: gcc ${CFLAGS} -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: c10/ex01/ft.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 22:32:41 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:44:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_H # define FT_H int ft_display_file(char *path); void ft_putchar_fd(char c, int fd); void ft_puterr(char *bin, char *path, char *error); void ft_putstr_fd(char *str, int fd); int ft_strcmp(char *s1, char *s2); int ft_strlen(char *str); #endif ================================================ FILE: c10/ex01/ft_display_file.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_display_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/14 22:17:46 by asoursou #+# #+# */ /* Updated: 2019/07/16 17:41:42 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include int ft_display_file(char *path) { char buf[2048]; int fd; int len; fd = (path) ? open(path, O_RDONLY) : STDIN_FILENO; if (fd < 0) return (-1); while ((len = read(fd, buf, 2048)) > 0) write(1, buf, len); if (fd != STDIN_FILENO) close(fd); return ((len) ? -1 : 0); } ================================================ FILE: c10/ex01/ft_putchar_fd.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar_fd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/15 16:10:45 by asoursou #+# #+# */ /* Updated: 2019/07/15 16:12:44 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar_fd(char c, int fd) { write(fd, &c, 1); } ================================================ FILE: c10/ex01/ft_puterr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_puterr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 17:15:38 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:43:18 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_puterr(char *bin, char *path, char *error) { ft_putstr_fd(bin, STDERR_FILENO); ft_putstr_fd(": ", STDERR_FILENO); ft_putstr_fd(path, STDERR_FILENO); ft_putstr_fd(": ", STDERR_FILENO); ft_putstr_fd(error, STDERR_FILENO); ft_putchar_fd('\n', STDERR_FILENO); } ================================================ FILE: c10/ex01/ft_putstr_fd.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr_fd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:42:27 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:43:32 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_putstr_fd(char *str, int fd) { write(fd, str, ft_strlen(str)); } ================================================ FILE: c10/ex01/ft_strcmp.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 01:25:21 by asoursou #+# #+# */ /* Updated: 2019/07/04 01:37:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strcmp(char *s1, char *s2) { while (*s1 && *s1 == *s2) { s1++; s2++; } return (*s1 - *s2); } ================================================ FILE: c10/ex01/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/03 15:18:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: c10/ex01/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:32:28 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:43:14 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "ft.h" int main(int argc, char **argv) { char *bin; int i; bin = basename(argv[0]); if (argc < 2 && ft_display_file(NULL) < 0) ft_puterr(bin, NULL, strerror(errno)); i = 0; while (++i < argc) { if (!ft_strcmp(argv[i], "-")) argv[i] = NULL; if (ft_display_file(argv[i]) < 0) ft_puterr(bin, argv[i], strerror(errno)); } return (0); } ================================================ FILE: c10/ex02/Makefile ================================================ SRCS = ft_atoi.c \ ft_putchar_fd.c \ ft_puterr.c \ ft_putstr_fd.c \ ft_strcmp.c \ ft_strlen.c \ ft_strncpy.c \ ft_tail.c \ main.c OBJS = ${SRCS:.c=.o} NAME = ft_tail CFLAGS = -Wall -Wextra -Werror all: ${NAME} ${NAME}: ${OBJS} gcc ${CFLAGS} $^ -o $@ .c.o: gcc ${CFLAGS} -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: c10/ex02/ft.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 22:32:41 by asoursou #+# #+# */ /* Updated: 2019/07/16 23:18:51 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_H # define FT_H int ft_atoi(char *str); int ft_display_file(char *path); void ft_putchar_fd(char c, int fd); void ft_puterr(char *bin, char *path, char *error); void ft_putstr_fd(char *str, int fd); int ft_strcmp(char *s1, char *s2); int ft_strlen(char *str); char *ft_strncpy(char *dest, char *src, unsigned int n); int ft_tail(char *path, unsigned int n, int count, int print_path); #endif ================================================ FILE: c10/ex02/ft_atoi.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 06:20:50 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:35:23 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_atoi(char *str) { int n; int negative; while ((*str >= 9 && *str <= 13) || *str == ' ') str++; negative = 0; while (*str == '-' || *str == '+') if (*str++ == '-') negative = 1 - negative; n = 0; while (*str >= '0' && *str <= '9') n = n * 10 + *str++ - '0'; if (negative) n *= -1; return (n); } ================================================ FILE: c10/ex02/ft_putchar_fd.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar_fd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/15 16:10:45 by asoursou #+# #+# */ /* Updated: 2019/07/15 16:12:44 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar_fd(char c, int fd) { write(fd, &c, 1); } ================================================ FILE: c10/ex02/ft_puterr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_puterr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 17:15:38 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:48:17 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_puterr(char *bin, char *path, char *error) { ft_putstr_fd(bin, STDERR_FILENO); ft_putstr_fd(": ", STDERR_FILENO); ft_putstr_fd(path, STDERR_FILENO); ft_putstr_fd(": ", STDERR_FILENO); ft_putstr_fd(error, STDERR_FILENO); ft_putchar_fd('\n', STDERR_FILENO); } ================================================ FILE: c10/ex02/ft_putstr_fd.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr_fd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:42:27 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:56:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_putstr_fd(char *str, int fd) { write(fd, str, ft_strlen(str)); } ================================================ FILE: c10/ex02/ft_strcmp.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/04 01:25:21 by asoursou #+# #+# */ /* Updated: 2019/07/04 01:37:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strcmp(char *s1, char *s2) { while (*s1 && *s1 == *s2) { s1++; s2++; } return (*s1 - *s2); } ================================================ FILE: c10/ex02/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/03 15:18:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: c10/ex02/ft_strncpy.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 22:19:59 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:20:01 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strncpy(char *dest, char *src, unsigned int n) { unsigned int i; i = -1; while (++i < n && src[i]) dest[i] = src[i]; while (i < n) dest[i++] = '\0'; return (dest); } ================================================ FILE: c10/ex02/ft_tail.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_tail.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/15 16:51:18 by asoursou #+# #+# */ /* Updated: 2019/07/16 23:47:01 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "ft.h" char *ft_load_file(int fd, unsigned int *size) { char buf[2048]; char *content; char *tmp; int len; if (!(content = malloc(sizeof(char)))) return (NULL); *content = '\0'; *size = 0; while ((len = read(fd, buf, 2048)) > 0) { if (!(tmp = malloc((*size + len) * sizeof(char)))) break ; tmp = ft_strncpy(tmp, content, *size); free(content); ft_strncpy(tmp + *size, buf, len); content = tmp; *size += len; content[*size] = '\0'; } if (len) free(content); return ((len) ? NULL : content); } int ft_tail(char *path, unsigned int n, int count, int print_path) { char *content; int fd; unsigned int size; fd = (path) ? open(path, O_RDONLY) : STDIN_FILENO; if (fd < 0) return (-1); content = ft_load_file(fd, &size); if (fd != STDIN_FILENO) close(fd); if (!content) return (-1); if (print_path) { if (count) ft_putchar_fd('\n', 1); ft_putstr_fd("==> ", 1); ft_putstr_fd(path, 1); ft_putstr_fd(" <==\n", 1); } if (n > size) n = size; ft_putstr_fd(content + size - n, 1); free(content); return (0); } ================================================ FILE: c10/ex02/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:32:28 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:55:02 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "ft.h" int main(int argc, char **argv) { char *bin; int i; int count; unsigned int n; if (argc < 3 || ft_strcmp(argv[1], "-c")) return (0); bin = basename(argv[0]); i = ft_atoi(argv[2]); n = (i < 0) ? -i : i; if (argc < 4 && ft_tail(NULL, n, 0, 0) < 0) ft_puterr(bin, NULL, strerror(errno)); i = 2; count = 0; while (++i < argc) { if (ft_tail(argv[i], n, count, argc > 4) < 0) ft_puterr(bin, argv[i], strerror(errno)); else count++; } return (0); } ================================================ FILE: c11/ex00/ft_foreach.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_foreach.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 21:06:37 by asoursou #+# #+# */ /* Updated: 2019/07/16 21:20:17 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_foreach(int *tab, int length, void (*f)(int)) { int i; i = 0; while (i < length) f(tab[i++]); } ================================================ FILE: c11/ex01/ft_map.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_map.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 21:17:48 by asoursou #+# #+# */ /* Updated: 2019/07/16 21:28:26 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include int *ft_map(int *tab, int length, int (*f)(int)) { int *ret; int i; if (length < 1 || !(ret = malloc(length * sizeof(int)))) return (NULL); i = -1; while (++i < length) ret[i] = f(tab[i]); return (ret); } ================================================ FILE: c11/ex02/ft_any.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_any.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 21:29:30 by asoursou #+# #+# */ /* Updated: 2019/07/17 01:42:50 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_any(char **tab, int (*f)(char*)) { int i; i = 0; while (tab[i]) if (f(tab[i++])) return (1); return (0); } ================================================ FILE: c11/ex03/ft_count_if.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_count_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 01:43:23 by asoursou #+# #+# */ /* Updated: 2019/07/17 03:40:08 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_count_if(char **tab, int length, int (*f)(char*)) { int i; int n; i = 0; n = 0; while (i < length) if (f(tab[i++])) n++; return (n); } ================================================ FILE: c11/ex04/ft_is_sort.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_is_sort.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 03:41:29 by asoursou #+# #+# */ /* Updated: 2019/07/18 00:10:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_is_sort(int *tab, int length, int (*f)(int, int)) { int i; int r; int r2; i = 1; while (i < length && !(r = f(tab[i - 1], tab[i]))) i++; while (i < length) { r2 = f(tab[i - 1], tab[i]); if ((r < 0 && r2 > 0) || (r > 0 && r2 < 0)) return (0); i++; } return (1); } ================================================ FILE: c11/ex05/Makefile ================================================ SRCS = ft_atoi.c \ ft_op.c \ ft_putchar.c \ ft_putnbr.c \ ft_putstr.c \ ft_strlen.c \ main.c OBJS = ${SRCS:.c=.o} NAME = do-op CFLAGS = -Wall -Wextra -Werror all: ${NAME} ${NAME}: ${OBJS} gcc ${CFLAGS} $^ -o $@ .c.o: gcc ${CFLAGS} -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: c11/ex05/ft.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 04:21:58 by asoursou #+# #+# */ /* Updated: 2019/07/17 14:42:52 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_H # define FT_H typedef enum e_op { op_sum, op_sub, op_div, op_mul, op_mod, op_null, } t_op; void ft_sum(int a, int b); void ft_sub(int a, int b); void ft_div(int a, int b); void ft_mul(int a, int b); void ft_mod(int a, int b); int ft_atoi(char *str); void ft_putchar(char c); void ft_putnbr(int nb); void ft_putstr(char *str); int ft_strlen(char *str); #endif ================================================ FILE: c11/ex05/ft_atoi.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 06:20:50 by asoursou #+# #+# */ /* Updated: 2019/07/07 02:35:23 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_atoi(char *str) { int n; int negative; while ((*str >= 9 && *str <= 13) || *str == ' ') str++; negative = 0; while (*str == '-' || *str == '+') if (*str++ == '-') negative = 1 - negative; n = 0; while (*str >= '0' && *str <= '9') n = n * 10 + *str++ - '0'; if (negative) n *= -1; return (n); } ================================================ FILE: c11/ex05/ft_op.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_do-op.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 05:08:56 by asoursou #+# #+# */ /* Updated: 2019/07/17 14:41:39 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft.h" void ft_sum(int a, int b) { ft_putnbr(a + b); } void ft_sub(int a, int b) { ft_putnbr(a - b); } void ft_div(int a, int b) { if (b) ft_putnbr(a / b); else ft_putstr("Stop : division by zero"); } void ft_mul(int a, int b) { ft_putnbr(a * b); } void ft_mod(int a, int b) { if (b) ft_putnbr(a % b); else ft_putstr("Stop : modulo by zero"); } ================================================ FILE: c11/ex05/ft_putchar.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:19:29 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:28:36 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } ================================================ FILE: c11/ex05/ft_putnbr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putnbr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/02 13:02:20 by asoursou #+# #+# */ /* Updated: 2019/07/17 13:41:50 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_putnbr(int nb) { unsigned int n; if (nb < 0) { ft_putchar('-'); n = -nb; } else n = nb; if (n > 9) { ft_putnbr(n / 10); n %= 10; } ft_putchar(n + '0'); } ================================================ FILE: c11/ex05/ft_putstr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:00:11 by asoursou #+# #+# */ /* Updated: 2019/07/17 05:37:21 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_putstr(char *str) { write(1, str, ft_strlen(str)); } ================================================ FILE: c11/ex05/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/03 15:18:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: c11/ex05/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 15:25:06 by asoursou #+# #+# */ /* Updated: 2019/07/17 15:25:16 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft.h" t_op ft_get_index(char *str) { if (!*str || str[1]) return (op_null); if (*str == '+') return (op_sum); if (*str == '-') return (op_sub); if (*str == '/') return (op_div); if (*str == '*') return (op_mul); if (*str == '%') return (op_mod); return (op_null); } int main(int argc, char **argv) { void (*do_op[5])(int, int); t_op op; do_op[op_sum] = &ft_sum; do_op[op_sub] = &ft_sub; do_op[op_div] = &ft_div; do_op[op_mul] = &ft_mul; do_op[op_mod] = &ft_mod; if (argc == 4) { op = ft_get_index(argv[2]); if (op == op_null) ft_putnbr(0); else do_op[op](ft_atoi(argv[1]), ft_atoi(argv[3])); ft_putchar('\n'); } return (0); } ================================================ FILE: c11/ex06/ft_sort_string_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sort_string_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 14:54:30 by asoursou #+# #+# */ /* Updated: 2019/07/17 15:12:29 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strcmp(char *s1, char *s2) { while (*s1 && *s1 == *s2) { s1++; s2++; } return (*s1 - *s2); } void ft_strswap(char **a, char **b) { char *c; c = *a; *a = *b; *b = c; } void ft_sort_str_tab(char **tab, int size) { char *pivot; int i; int j; if (size < 2) return ; pivot = tab[--size]; i = 0; j = -1; while (++j < size) if (ft_strcmp(tab[j], pivot) < 0) ft_strswap(&tab[i++], &tab[j]); if (ft_strcmp(tab[i], tab[size]) > 0) ft_strswap(&tab[i], &tab[size]); ft_sort_str_tab(tab, i); ft_sort_str_tab(tab + i + 1, size - i); } void ft_sort_string_tab(char **tab) { int n; n = 0; while (tab[n]) n++; ft_sort_str_tab(tab, n); } ================================================ FILE: c11/ex07/ft_advanced_sort_string_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_advanced_sort_string_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 15:09:08 by asoursou #+# #+# */ /* Updated: 2019/07/18 01:06:40 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_strswap(char **a, char **b) { char *c; c = *a; *a = *b; *b = c; } void ft_advanced_sort_string_tab(char **tab, int (*cmp)(char *, char *)) { int size; int i; size = 0; while (tab[size]) size++; while (--size >= 0) { i = 0; while (++i <= size) if (cmp(tab[i - 1], tab[i]) > 0) ft_strswap(&tab[i - 1], &tab[i]); } } ================================================ FILE: c12/Makefile ================================================ SRCS = ex00/ft_create_elem.c \ ex01/ft_list_push_front.c \ ex02/ft_list_size.c \ ex03/ft_list_last.c \ ex04/ft_list_push_back.c \ ex05/ft_list_push_strs.c \ ex06/ft_list_clear.c \ ex07/ft_list_at.c \ ex08/ft_list_reverse.c \ ex09/ft_list_foreach.c \ ex10/ft_list_foreach_if.c \ ex11/ft_list_find.c \ ex12/ft_list_remove_if.c \ ex13/ft_list_merge.c \ ex14/ft_list_sort.c \ ex15/ft_list_reverse_fun.c \ ex16/ft_sorted_list_insert.c \ ex17/ft_sorted_list_merge.c \ main.c OBJS = ${SRCS:.c=.o} NAME = a.out CFLAGS = -Wall -Wextra -Werror all: ${NAME} ${NAME}: ${OBJS} gcc ${CFLAGS} $^ -o $@ .c.o: gcc ${CFLAGS} -I. -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: c12/ex00/ft_create_elem.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_create_elem.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 01:38:16 by asoursou #+# #+# */ /* Updated: 2019/07/18 02:17:18 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" t_list *ft_create_elem(void *data) { t_list *l; if (!(l = malloc(sizeof(t_list)))) return (NULL); l->next = NULL; l->data = data; return (l); } ================================================ FILE: c12/ex00/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex01/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex01/ft_list_push_front.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_push_front.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 04:53:41 by asoursou #+# #+# */ /* Updated: 2019/07/18 18:44:21 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_list_push_front(t_list **begin_list, void *data) { t_list *e; if ((e = ft_create_elem(data))) { if (*begin_list) e->next = *begin_list; *begin_list = e; } } ================================================ FILE: c12/ex02/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex02/ft_list_size.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_size.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 19:33:22 by asoursou #+# #+# */ /* Updated: 2019/07/19 02:53:06 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" int ft_list_size(t_list *begin_list) { return ((begin_list) ? 1 + ft_list_size(begin_list->next) : 0); } ================================================ FILE: c12/ex03/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex03/ft_list_last.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_last.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 19:47:55 by asoursou #+# #+# */ /* Updated: 2019/07/19 02:55:35 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" t_list *ft_list_last(t_list *begin_list) { if (!begin_list || !begin_list->next) return (begin_list); return (ft_list_last(begin_list->next)); } ================================================ FILE: c12/ex04/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex04/ft_list_push_back.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_push_back.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 20:41:20 by asoursou #+# #+# */ /* Updated: 2019/07/18 20:44:26 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_list_push_back(t_list **begin_list, void *data) { if (!*begin_list) *begin_list = ft_create_elem(data); else if ((*begin_list)->next) ft_list_push_back(&(*begin_list)->next, data); else (*begin_list)->next = ft_create_elem(data); } ================================================ FILE: c12/ex05/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex05/ft_list_push_strs.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_push_strs.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 20:42:07 by asoursou #+# #+# */ /* Updated: 2019/07/19 02:51:11 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" t_list *ft_list_push_strs(int size, char **strs) { t_list *begin; t_list *e; int i; begin = NULL; i = -1; while (++i < size && (e = ft_create_elem(strs[i]))) { e->next = begin; begin = e; } return (begin); } ================================================ FILE: c12/ex06/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex06/ft_list_clear.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_clear.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 18:15:02 by asoursou #+# #+# */ /* Updated: 2019/07/19 02:52:16 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)) { if (!begin_list) return ; ft_list_clear(begin_list->next, free_fct); if (free_fct) free_fct(begin_list->data); free(begin_list); } ================================================ FILE: c12/ex07/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex07/ft_list_at.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_at.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 00:30:41 by asoursou #+# #+# */ /* Updated: 2019/07/19 00:45:34 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" t_list *ft_list_at(t_list *begin_list, unsigned int nbr) { if (!begin_list || !nbr) return (begin_list); return (ft_list_at(begin_list->next, nbr - 1)); } ================================================ FILE: c12/ex08/ft_list_reverse.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_reverse.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 00:52:44 by asoursou #+# #+# */ /* Updated: 2019/07/20 03:13:57 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" void ft_list_reverse(t_list **begin_list) { t_list *prev; t_list *next; prev = NULL; while (*begin_list) { next = (*begin_list)->next; (*begin_list)->next = prev; prev = *begin_list; *begin_list = next; } *begin_list = prev; } ================================================ FILE: c12/ex09/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex09/ft_list_foreach.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_foreach.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 19:02:55 by asoursou #+# #+# */ /* Updated: 2019/07/18 19:06:35 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_list_foreach(t_list *begin_list, void (*f)(void *)) { if (!begin_list) return ; f(begin_list->data); ft_list_foreach(begin_list->next, f); } ================================================ FILE: c12/ex10/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex10/ft_list_foreach_if.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_foreach_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 02:26:37 by asoursou #+# #+# */ /* Updated: 2019/07/19 02:42:30 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), void *data_ref, int (*cmp)()) { if (!begin_list) return ; if (!cmp(begin_list->data, data_ref)) f(begin_list->data); ft_list_foreach_if(begin_list->next, f, data_ref, cmp); } ================================================ FILE: c12/ex11/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex11/ft_list_find.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_find.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 02:44:24 by asoursou #+# #+# */ /* Updated: 2019/07/19 03:03:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()) { if (!begin_list || !cmp(begin_list->data, data_ref)) return (begin_list); return (ft_list_find(begin_list->next, data_ref, cmp)); } ================================================ FILE: c12/ex12/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex12/ft_list_remove_if.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_remove_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 03:08:37 by asoursou #+# #+# */ /* Updated: 2019/07/20 03:02:35 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *)) { t_list *prev; t_list *l; prev = NULL; l = *begin_list; while (l) if (!cmp(l->data, data_ref)) { if (prev) prev->next = l->next; else *begin_list = l->next; if (free_fct) free_fct(l->data); free(l); l = (prev) ? prev->next : *begin_list; } else { prev = l; l = l->next; } } ================================================ FILE: c12/ex13/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex13/ft_list_merge.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_merge.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 04:09:39 by asoursou #+# #+# */ /* Updated: 2019/07/19 05:03:46 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_list_merge(t_list **begin_list1, t_list *begin_list2) { if (!*begin_list1) *begin_list1 = begin_list2; else if ((*begin_list1)->next) ft_list_merge(&(*begin_list1)->next, begin_list2); else (*begin_list1)->next = begin_list2; } ================================================ FILE: c12/ex14/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex14/ft_list_sort.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_sort.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 04:32:07 by asoursou #+# #+# */ /* Updated: 2019/07/19 07:02:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" t_list *ft_merge(t_list *l1, t_list *l2, int (*cmp)()) { if (!l1) return (l2); if (!l2) return (l1); if (cmp(l1->data, l2->data) > 0) { l2->next = ft_merge(l1, l2->next, cmp); return (l2); } l1->next = ft_merge(l1->next, l2, cmp); return (l1); } void ft_list_sort(t_list **begin_list, int (*cmp)()) { t_list *prev; t_list *next; if (!*begin_list || !(*begin_list)->next) return ; prev = *begin_list; next = prev->next; while (next && (next = next->next)) { prev = prev->next; next = next->next; } next = prev->next; prev->next = NULL; ft_list_sort(&(*begin_list), cmp); ft_list_sort(&next, cmp); *begin_list = ft_merge(*begin_list, next, cmp); } ================================================ FILE: c12/ex15/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex15/ft_list_reverse_fun.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_reverse_fun.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 03:08:18 by asoursou #+# #+# */ /* Updated: 2019/07/22 04:31:55 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" static int ft_list_size(t_list *begin_list) { return ((begin_list) ? 1 + ft_list_size(begin_list->next) : 0); } static t_list *ft_list_at(t_list *begin_list, unsigned int nbr) { if (!begin_list || !nbr) return (begin_list); return (ft_list_at(begin_list->next, nbr - 1)); } void ft_list_reverse_fun(t_list *begin_list) { t_list *right; void *data; unsigned int i; unsigned int j; i = -1; while (begin_list && (j = ft_list_size(begin_list) - ++i) > 1) { right = ft_list_at(begin_list, j - 1); data = begin_list->data; begin_list->data = right->data; right->data = data; begin_list = begin_list->next; } } ================================================ FILE: c12/ex16/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex16/ft_sorted_list_insert.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sorted_list_insert.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 03:43:01 by asoursou #+# #+# */ /* Updated: 2019/07/20 04:26:57 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)()) { t_list *e; if (!*begin_list || cmp(data, (*begin_list)->data) <= 0) { if (!(e = ft_create_elem(data))) return ; e->next = *begin_list; *begin_list = e; } else ft_sorted_list_insert(&(*begin_list)->next, data, cmp); } ================================================ FILE: c12/ex17/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/18 04:51:31 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); #endif ================================================ FILE: c12/ex17/ft_sorted_list_merge.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sorted_list_merge.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 04:35:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 05:18:09 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_sorted_list_insert_elem(t_list **l, t_list *elem, int (*cmp)()) { if (!*l || cmp(elem->data, (*l)->data) <= 0) { elem->next = *l; *l = elem; } else ft_sorted_list_insert_elem(&(*l)->next, elem, cmp); } void ft_sorted_list_merge(t_list **begin_list1, t_list *begin_list2, int (*cmp)()) { if (!begin_list2) return ; ft_sorted_list_merge(begin_list1, begin_list2->next, cmp); ft_sorted_list_insert_elem(begin_list1, begin_list2, cmp); } ================================================ FILE: c12/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/22 01:41:33 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); void ft_list_push_front(t_list **begin_list, void *data); int ft_list_size(t_list *begin_list); t_list *ft_list_last(t_list *begin_list); void ft_list_push_back(t_list **begin_list, void *data); t_list *ft_list_push_strs(int size, char **strs); void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); t_list *ft_list_at(t_list *begin_list, unsigned int nbr); void ft_list_reverse(t_list **begin_list); void ft_list_foreach(t_list *begin_list, void (*f)(void *)); void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), void *data_ref, int (*cmp)()); t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *)); void ft_list_merge(t_list **begin_list1, t_list *begin_list2); void ft_list_sort(t_list **begin_list, int (*cmp)()); void ft_list_reverse_fun(t_list *begin_list); void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)()); void ft_sorted_list_merge(t_list **begin_list1, t_list *begin_list2, int (*cmp)()); #endif ================================================ FILE: c12/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 04:23:59 by asoursou #+# #+# */ /* Updated: 2019/07/22 01:41:59 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "ft_list.h" void ft_list_print(t_list *l) { if (!l) { printf("NULL\n"); return ; } printf("%s -> ", (char *)l->data); ft_list_print(l->next); } t_list *ft_list_create(void) { t_list *l; l = NULL; ft_list_push_back(&l, "a"); ft_list_push_back(&l, "b"); ft_list_push_back(&l, "c"); return (l); } int main(int argc, char **argv) { t_list *l; t_list *e; l = ft_list_push_strs(argc - 1, argv + 1); printf("content: "); ft_list_print(l); printf("size: %d\n", ft_list_size(l)); e = ft_list_at(l, 1); printf("2nd element: "); if (e) printf("%s\n", e->data); else printf("NULL\n"); ft_list_reverse_fun(l); printf("reverse content: "); ft_list_print(l); ft_list_sort(&l, &strcmp); printf("sorted content: "); ft_list_print(l); ft_list_remove_if(&l, "foo", &strcmp, NULL); printf("removing foo: "); ft_list_print(l); ft_sorted_list_insert(&l, "foo", &strcmp); printf("inserting foo: "); ft_list_print(l); ft_sorted_list_merge(&l, ft_list_create(), &strcmp); printf("merging a b c: "); ft_list_print(l); ft_list_clear(l, NULL); return (0); } ================================================ FILE: c13/Makefile ================================================ SRCS = ex00/btree_create_node.c \ ex01/btree_apply_prefix.c \ ex02/btree_apply_infix.c \ ex03/btree_apply_suffix.c \ ex04/btree_insert_data.c \ ex05/btree_search_item.c \ ex06/btree_level_count.c \ ex07/btree_apply_by_level.c \ main.c OBJS = ${SRCS:.c=.o} NAME = a.out CFLAGS = -Wall -Wextra -Werror all: ${NAME} ${NAME}: ${OBJS} gcc ${CFLAGS} $^ -o $@ .c.o: gcc ${CFLAGS} -I. -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: c13/ex00/btree_create_node.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_create_node.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:57:41 by asoursou #+# #+# */ /* Updated: 2019/07/20 07:22:15 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_btree.h" t_btree *btree_create_node(void *item) { t_btree *b; if ((b = malloc(sizeof(t_btree)))) { b->left = NULL; b->right = NULL; b->item = item; } return (b); } ================================================ FILE: c13/ex00/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ex01/btree_apply_prefix.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_apply_prefix.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 07:19:06 by asoursou #+# #+# */ /* Updated: 2019/07/25 03:01:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_btree.h" void btree_apply_prefix(t_btree *root, void (*applyf)(void *)) { if (!root) return ; applyf(root->item); btree_apply_prefix(root->left, applyf); btree_apply_prefix(root->right, applyf); } ================================================ FILE: c13/ex01/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ex02/btree_apply_infix.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_apply_infix.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 07:25:52 by asoursou #+# #+# */ /* Updated: 2019/07/25 03:01:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_btree.h" void btree_apply_infix(t_btree *root, void (*applyf)(void *)) { if (!root) return ; btree_apply_infix(root->left, applyf); applyf(root->item); btree_apply_infix(root->right, applyf); } ================================================ FILE: c13/ex02/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ex03/btree_apply_suffix.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_apply_suffix.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 07:27:10 by asoursou #+# #+# */ /* Updated: 2019/07/25 03:01:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_btree.h" void btree_apply_suffix(t_btree *root, void (*applyf)(void *)) { if (!root) return ; btree_apply_suffix(root->left, applyf); btree_apply_suffix(root->right, applyf); applyf(root->item); } ================================================ FILE: c13/ex03/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ex04/btree_insert_data.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_insert_data.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 07:35:38 by asoursou #+# #+# */ /* Updated: 2019/07/22 09:22:27 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_btree.h" void btree_insert_data(t_btree **root, void *item, int (*cmpf)(void *, void *)) { if (!*root) *root = btree_create_node(item); else if (cmpf(item, (*root)->item) < 0) btree_insert_data(&(*root)->left, item, cmpf); else btree_insert_data(&(*root)->right, item, cmpf); } ================================================ FILE: c13/ex04/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ex05/btree_search_item.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_search_item.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 07:44:38 by asoursou #+# #+# */ /* Updated: 2019/07/25 06:26:54 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_btree.h" void *btree_search_item(t_btree *root, void *data_ref, int (*cmpf)(void *, void *)) { void *item; if (!root) return (NULL); if ((item = btree_search_item(root->left, data_ref, cmpf))) return (item); if (!cmpf(data_ref, root->item)) return (root->item); return (btree_search_item(root->right, data_ref, cmpf)); } ================================================ FILE: c13/ex05/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ex06/btree_level_count.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_level_count.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/22 10:36:51 by asoursou #+# #+# */ /* Updated: 2019/07/22 10:39:26 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_btree.h" int btree_level_count(t_btree *root) { int left; int right; if (!root) return (0); left = btree_level_count(root->left); right = btree_level_count(root->right); return (1 + ((left > right) ? left : right)); } ================================================ FILE: c13/ex06/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ex07/btree_apply_by_level.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* btree_apply_by_level.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/22 10:42:49 by asoursou #+# #+# */ /* Updated: 2019/07/25 09:47:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_btree.h" static int btree_level_count(t_btree *root) { int left; int right; if (!root) return (0); left = btree_level_count(root->left); right = btree_level_count(root->right); return (1 + ((left > right) ? left : right)); } void btree_process_level(t_btree *root, int *t, int level, void (*applyf)(void *item, int current_level, int is_first_elem)) { if (!root) return ; if (level == 1) { applyf(root->item, t[0], t[1]); t[1] = 0; } else if (level > 1) { btree_process_level(root->left, t, level - 1, applyf); btree_process_level(root->right, t, level - 1, applyf); } } void btree_apply_by_level(t_btree *root, void (*applyf)(void *item, int current_level, int is_first_elem)) { int t[3]; int h; int i; if (!root) return ; h = btree_level_count(root); i = 0; while (i < h) { t[0] = i; t[1] = 1; btree_process_level(root, t, ++i, applyf); } } ================================================ FILE: c13/ex07/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/20 06:59:25 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); #endif ================================================ FILE: c13/ft_btree.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_btree.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:50:29 by asoursou #+# #+# */ /* Updated: 2019/07/25 00:24:37 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H # define FT_BTREE_H typedef struct s_btree { struct s_btree *left; struct s_btree *right; void *item; } t_btree; t_btree *btree_create_node(void *item); void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); void btree_apply_infix(t_btree *root, void (*applyf)(void *)); void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); void btree_insert_data(t_btree **root, void *item, int (*cmpf)(void *, void *)); void *btree_search_item(t_btree *root, void *data_ref, int (*cmpf)(void *, void *)); int btree_level_count(t_btree *root); void btree_apply_by_level(t_btree *root, void (*applyf)(void*item, int current_level, int is_first_elem)); #endif ================================================ FILE: c13/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 06:13:56 by asoursou #+# #+# */ /* Updated: 2019/07/25 09:42:14 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "ft_btree.h" void btree_clear(t_btree *root) { if (!root) return ; btree_clear(root->left); btree_clear(root->right); free(root); } void btree_print(t_btree *node, unsigned int deep) { unsigned int i; if (!node) return ; if (deep) { i = 0; while (++i < deep) printf(" "); printf("↳ "); } printf("%s\n", node->item); btree_print(node->left, deep + 1); btree_print(node->right, deep + 1); } void btree_ultimate_print(void *item, int level, int is_first_elem) { printf("[%s] l:[%d] f:[%d]\n", item, level, is_first_elem); } int ft_fakestrcmp(void *s1, void *s2) { return (strcmp(s1, s2)); } int main(int argc, char **argv) { t_btree *b; int i; if (argc < 1) return (0); b = NULL; i = 1; while (i < argc) btree_insert_data(&b, argv[i++], &ft_fakestrcmp); btree_print(b, 0); btree_apply_by_level(b, &btree_ultimate_print); if (btree_search_item(b, "foo", &ft_fakestrcmp)) printf("foo found!\n"); printf("height: %d\n", btree_level_count(b)); btree_clear(b); return (0); } ================================================ FILE: other/binary.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* binary.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 17:33:35 by asoursou #+# #+# */ /* Updated: 2019/07/06 17:46:50 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } // fonction qui affiche un caractere en hexadecimal void ft_puthex(unsigned char c) { char *base; base = "0123456789abcdef"; // c >> 4 recupere la dizaine ft_putchar(base[c >> 4]); // c & 0xf recupere l'unite (== c % 16) ft_putchar(base[c & 0xf]); } int main(void) { unsigned int n = 0x41424344; // "ABCD", len = 4 octets = 32 bit // on affiche uniquement le 'B' en hexadecimal (valeur en ascii = 66 = 42 en base 16) ft_puthex(n >> 16); ft_putchar('\n'); // on affiche le 'B' en ascii ft_putchar(n >> 16); return (0); } ================================================ FILE: other/mkdirs.sh ================================================ #!/bin/bash if [ "$#" != "1" ]; then echo "error: Invalid argument" exit fi n=$1 while [ "$n" -ge "0" ]; do if [ "$n" -lt "10" ] then mkdir -p "ex0$n" else mkdir -p "ex$n" fi n=`expr "$n" - 1`; done ================================================ FILE: other/sorting.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* sorting.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 04:39:28 by asoursou #+# #+# */ /* Updated: 2019/07/19 04:47:28 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include int ft_is_sorted(int *tab, int size) { while (--size > 0) if (tab[size] < tab[size - 1]) return (0); return (1); } void ft_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; } void ft_sort_int_tab(int *tab, int size) { int pivot; int i; int j; if (size < 2) return ; pivot = tab[--size]; i = 0; j = -1; while (++j < size) if (tab[j] < pivot) ft_swap(&tab[i++], &tab[j]); if (tab[i] > tab[size]) ft_swap(&tab[i], &tab[size]); ft_sort_int_tab(tab, i); ft_sort_int_tab(tab + i + 1, size - i); } void ft_bubble_sort(int *tab, int size) { int i, j; for (i = size - 1; i >= 0; i--) for (j = 1; j <= i; j++) if (tab[j - 1] > tab[j]) ft_swap(&tab[j - 1], &tab[j]); } void benchmark(char *name, int n, void(*sorting)(int *, int)) { clock_t start, end; int t[n]; srand(0); for (int i = 0; i < n; i++) t[i] = rand(); printf("%s:\n", name); start = clock(); sorting(t, n); end = clock(); printf("time: %f\n", (double)(end - start) / CLOCKS_PER_SEC); //printf("sorted: %d\n", ft_is_sorted(t, n)); } int main(int argc, char **argv) { if (argc != 2) return (0); int n = atoi(argv[1]); if (n >= 1 && n <= 100000) { benchmark("ft_sort_int_tab", n, ft_sort_int_tab); benchmark("ft_bubble_sort", n, ft_bubble_sort); } return (0); } ================================================ FILE: rush00/ex00/ft_putchar.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tbrondin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 16:53:35 by tbrondin #+# #+# */ /* Updated: 2019/07/06 16:53:39 by tbrondin ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } ================================================ FILE: rush00/ex00/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tbrondin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 16:54:19 by tbrondin #+# #+# */ /* Updated: 2019/07/07 23:38:59 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void rush(int x, int y); int ft_atoi(char *str) { int n; int negative; while ((*str >= 9 && *str <= 13) || *str == ' ') str++; negative = 0; while (*str == '-' || *str == '+') if (*str++ == '-') negative = 1 - negative; n = 0; while (*str >= '0' && *str <= '9') n = n * 10 + *str++ - '0'; if (negative) n *= -1; return (n); } int main(int argc, char **argv) { if (argc == 3) rush(ft_atoi(argv[1]), ft_atoi(argv[2])); return (0); } ================================================ FILE: rush00/ex00/rush00.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* rush00.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tbrondin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 17:05:10 by tbrondin #+# #+# */ /* Updated: 2019/07/06 18:20:13 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_putchar(char c); void ft_print_line(char left, char middle, char right, int size) { ft_putchar(left); while (size-- > 2) ft_putchar(middle); if (size == 1) ft_putchar(right); ft_putchar('\n'); } void rush(int x, int y) { if (x < 1 || y < 1) return ; ft_print_line('o', '-', 'o', x); while (y-- > 2) ft_print_line('|', ' ', '|', x); if (y == 1) ft_print_line('o', '-', 'o', x); } ================================================ FILE: rush00/ex00/rush01.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* rush01.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tbrondin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 16:51:38 by tbrondin #+# #+# */ /* Updated: 2019/07/06 18:20:01 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_putchar(char c); void ft_print_line(char left, char middle, char right, int size) { ft_putchar(left); while (size-- > 2) ft_putchar(middle); if (size == 1) ft_putchar(right); ft_putchar('\n'); } void rush(int x, int y) { if (x < 1 || y < 1) return ; ft_print_line('/', '*', '\\', x); while (y-- > 2) ft_print_line('*', ' ', '*', x); if (y == 1) ft_print_line('\\', '*', '/', x); } ================================================ FILE: rush00/ex00/rush02.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* rush02.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: alboumed +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 17:15:54 by alboumed #+# #+# */ /* Updated: 2019/07/06 18:20:24 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_putchar(char c); void ft_print_line(char left, char middle, char right, int size) { ft_putchar(left); while (size-- > 2) ft_putchar(middle); if (size == 1) ft_putchar(right); ft_putchar('\n'); } void rush(int x, int y) { if (x < 1 || y < 1) return ; ft_print_line('A', 'B', 'A', x); while (y-- > 2) ft_print_line('B', ' ', 'B', x); if (y == 1) ft_print_line('C', 'B', 'C', x); } ================================================ FILE: rush00/ex00/rush03.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* rush03.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tbrondin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 17:09:43 by tbrondin #+# #+# */ /* Updated: 2019/07/06 18:20:33 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_putchar(char c); void ft_print_line(char left, char middle, char right, int size) { ft_putchar(left); while (size-- > 2) ft_putchar(middle); if (size == 1) ft_putchar(right); ft_putchar('\n'); } void rush(int x, int y) { if (x < 1 || y < 1) return ; ft_print_line('A', 'B', 'C', x); while (y-- > 2) ft_print_line('B', ' ', 'B', x); if (y == 1) ft_print_line('A', 'B', 'C', x); } ================================================ FILE: rush00/ex00/rush04.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* rush04.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tbrondin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/06 17:13:36 by tbrondin #+# #+# */ /* Updated: 2019/07/06 18:21:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_putchar(char c); void ft_print_line(char left, char middle, char right, int size) { ft_putchar(left); while (size-- > 2) ft_putchar(middle); if (size == 1) ft_putchar(right); ft_putchar('\n'); } void rush(int x, int y) { if (x < 1 || y < 1) return ; ft_print_line('A', 'B', 'C', x); while (y-- > 2) ft_print_line('B', ' ', 'B', x); if (y == 1) ft_print_line('C', 'B', 'A', x); } ================================================ FILE: rush01/ex00/ft_backtrack.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_backtrack.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/14 10:48:54 by asoursou #+# #+# */ /* Updated: 2019/07/14 21:19:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_rush.h" int ft_is_valid_value(char **tab, int x, int y, int size) { if (ft_is_duplicate(tab, x, y, size) || ft_height_col(tab, x, 1, size) > tab[x][size] || (y == size - 1 && ft_height_col(tab, x, -1, size) != tab[x][size + 1]) || ft_height_row(tab, y, 1, size) > tab[y][size + 2] || (x == size - 1 && ft_height_row(tab, y, -1, size) != tab[y][size + 3])) return (0); return (1); } int ft_backtrack(char **tab, int n, int size) { int i; int x; int y; if (n == size * size) return (1); i = 0; x = n % size; y = n / size; while (++i <= size) { tab[y][x] = i; if (ft_is_valid_value(tab, x, y, size)) { if (ft_backtrack(tab, n + 1, size)) return (1); tab[y][x] = 0; } } tab[y][x] = 0; return (0); } int ft_solve(char **tab, int size) { int i; i = -1; while (++i < size) if (tab[i][size] + tab[i][size + 1] > size + 1 || tab[i][size + 2] + tab[i][size + 3] > size + 1) return (0); return (ft_backtrack(tab, 0, size)); } ================================================ FILE: rush01/ex00/ft_check.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_check.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/14 13:05:13 by asoursou #+# #+# */ /* Updated: 2019/07/14 19:55:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_height_col(char **tab, int x, int delta, int size) { int y; int max; int vmax; int height; y = (delta > 0) ? 0 : size - 1; max = (delta > 0) ? size : -1; vmax = 0; height = 0; while (y != max) { if (!tab[y][x]) return (0); if (tab[y][x] > vmax) { vmax = tab[y][x]; height++; } y += delta; } return (height); } int ft_height_row(char **tab, int y, int delta, int size) { int x; int max; int vmax; int height; x = (delta > 0) ? 0 : size - 1; max = (delta > 0) ? size : -1; vmax = 0; height = 0; while (x != max) { if (tab[y][x] > vmax) { vmax = tab[y][x]; height++; } x += delta; } return (height); } int ft_is_duplicate(char **tab, int x, int y, int size) { int i; if (!tab[y][x]) return (0); i = y; while (i--) if (tab[y][x] == tab[i][x]) return (1); i = y; while (++i < size) if (tab[y][x] == tab[i][x]) return (1); i = x; while (i--) if (tab[y][x] == tab[y][i]) return (1); i = x; while (++i < size) if (tab[y][x] == tab[y][i]) return (1); return (0); } ================================================ FILE: rush01/ex00/ft_destroy_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_destroy_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/14 10:51:18 by asoursou #+# #+# */ /* Updated: 2019/07/14 20:04:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_rush.h" void ft_destroy_tab(char **tab, int size) { while (size--) free(tab[size]); free(tab); } ================================================ FILE: rush01/ex00/ft_get_size.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_get_size.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/13 13:02:06 by asoursou #+# #+# */ /* Updated: 2019/07/14 21:20:47 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_is_valid(char *str, int size) { int i; int j; i = -1; j = size / 4; while (++i < size) { if (*str < '1' || *str > j + '0') return (0); str += 2; } return (j); } int ft_get_size(char *str) { int size; int i; size = 0; i = 0; while (str[i]) { if (str[i] >= '1' && str[i] <= '9') size++; else return (0); if (str[++i] == ' ' && !str[++i]) return (0); } if (size != 16) return (0); return (ft_is_valid(str, size)); } ================================================ FILE: rush01/ex00/ft_init_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_init_tab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/13 13:01:28 by asoursou #+# #+# */ /* Updated: 2019/07/14 12:17:04 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include char **ft_init_tab(char *str, int size) { char **tab; int x; int y; if (!(tab = malloc(size * sizeof(char*)))) return (NULL); y = -1; while (++y < size) { if (!(tab[y] = malloc((size + 4) * sizeof(char)))) return (NULL); x = -1; while (++x < size) tab[y][x] = 0; x = -1; while (++x < 4) tab[y][size + x] = str[2 * (y + x * size)] - '0'; } return (tab); } ================================================ FILE: rush01/ex00/ft_print_tab.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_printtab.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ogrosset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/13 12:22:29 by ogrosset #+# #+# */ /* Updated: 2019/07/14 20:31:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_rush.h" void ft_print_tab(char **tab, int size) { int x; int y; y = 0; while (y < size) { x = 0; while (x < size) { ft_putchar(tab[y][x] + '0'); if (++x < size) ft_putchar(' '); } ft_putchar('\n'); y++; } } ================================================ FILE: rush01/ex00/ft_putchar.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/13 10:25:09 by asoursou #+# #+# */ /* Updated: 2019/07/13 10:38:04 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } ================================================ FILE: rush01/ex00/ft_putstr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/13 10:27:01 by asoursou #+# #+# */ /* Updated: 2019/07/14 20:05:23 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_rush.h" void ft_putstr(char *str) { while (*str) ft_putchar(*str++); } ================================================ FILE: rush01/ex00/ft_rush.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_rush.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/14 20:03:57 by asoursou #+# #+# */ /* Updated: 2019/07/14 21:08:10 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_RUSH_H # define FT_RUSH_H void ft_putchar(char c); void ft_putstr(char *str); int ft_get_size(char *str); char **ft_init_tab(char *str, int size); int ft_solve(char **tab, int size); void ft_print_tab(char **tab, int size); void ft_destroy_tab(char **tab, int size); int ft_height_col(char **tab, int x, int delta, int size); int ft_height_row(char **tab, int y, int delta, int size); int ft_is_duplicate(char **tab, int x, int y, int size); #endif ================================================ FILE: rush01/ex00/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/13 10:25:54 by asoursou #+# #+# */ /* Updated: 2019/07/14 21:07:52 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_rush.h" void ft_error_message(void) { ft_putstr("Error\n"); } int main(int argc, char **argv) { char **tab; int size; if (argc != 2 || !(size = ft_get_size(argv[1]))) ft_error_message(); else if ((tab = ft_init_tab(argv[1], size))) { if (ft_solve(tab, size)) ft_print_tab(tab, size); ft_destroy_tab(tab, size); } else ft_error_message(); return (0); } ================================================ FILE: rush02/ex00/Makefile ================================================ SRCS = ft/ft_atol.c \ ft/ft_check_args.c \ ft/ft_file_load.c \ ft/ft_isdigit.c \ ft/ft_isprint.c \ ft/ft_is_valid.c \ ft/ft_isspace.c \ ft/ft_putchar.c \ ft/ft_putstr.c \ ft/ft_strlen.c \ ft/ft_strncpy.c \ ft_dict/ft_dict_cmp.c \ ft_dict/ft_dict_clear.c \ ft_dict/ft_dict_create.c \ ft_dict/ft_dict_create_elem.c \ ft_dict/ft_dict_in.c \ ft_dict/ft_print.c \ ft_list/ft_create_elem.c \ ft_list/ft_list_clear.c \ ft_list/ft_list_find.c \ ft_list/ft_sorted_list_insert.c \ main.c OBJS = $(addprefix srcs/, ${SRCS:.c=.o}) NAME = rush-02 CFLAGS = -Wall -Wextra -Werror all: ${NAME} ${NAME}: ${OBJS} gcc ${CFLAGS} $^ -o $@ .c.o: gcc ${CFLAGS} -I./includes -c $< -o ${<:.c=.o} clean: rm -f ${OBJS} fclean: clean rm -f ${NAME} re: fclean all .PHONY: all clean fclean re ================================================ FILE: rush02/ex00/includes/ft.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 21:38:33 by asoursou #+# #+# */ /* Updated: 2019/07/21 21:48:57 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_H # define FT_H void ft_check_args(int argc, char **argv, char **path, char **value); char *ft_file_load(char *path); int ft_is_valid(char *value); long ft_atol(char *str); int ft_isdigit(char c); int ft_isprint(char c); int ft_isspace(char c); void ft_putchar(char c); void ft_putstr(char *str); int ft_strlen(char *str); char *ft_strncpy(char *dest, char *src, unsigned int n); #endif ================================================ FILE: rush02/ex00/includes/ft_dict.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_dict.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 00:10:08 by asoursou #+# #+# */ /* Updated: 2019/07/21 10:57:35 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_DICT_H # define FT_DICT_H # include "ft_list.h" typedef struct s_data { unsigned long value; char *name; } t_data; t_list *ft_dict_create(char *content); t_data *ft_dict_create_elem(unsigned long value, char *name); t_data *ft_dict_in(t_list *dict, unsigned long value); int ft_dict_cmp(t_data *d1, t_data *d2); void ft_dict_clear(t_data *d); void ft_print(t_list *dict, char *value); #endif ================================================ FILE: rush02/ex00/includes/ft_list.h ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 18:47:15 by asoursou #+# #+# */ /* Updated: 2019/07/21 03:25:33 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H # define FT_LIST_H typedef struct s_list { struct s_list *next; void *data; } t_list; t_list *ft_create_elem(void *data); void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)()); t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); void ft_list_clear(t_list *begin_list, void (*free_fct)()); #endif ================================================ FILE: rush02/ex00/numbers.dict ================================================ 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 ================================================ FILE: rush02/ex00/srcs/ft/ft_atol.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atol.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 01:49:38 by asoursou #+# #+# */ /* Updated: 2019/07/21 01:49:40 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ long ft_atol(char *str) { long n; int negative; while ((*str >= 9 && *str <= 13) || *str == ' ') str++; negative = 0; while (*str == '-' || *str == '+') if (*str++ == '-') negative = 1 - negative; n = 0; while (*str >= '0' && *str <= '9') n = n * 10 + *str++ - '0'; if (negative) n *= -1; return (n); } ================================================ FILE: rush02/ex00/srcs/ft/ft_check_args.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_check_args.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hvernhes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 23:54:34 by hvernhes #+# #+# */ /* Updated: 2019/07/21 00:27:39 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_check_args(int argc, char **argv, char **path, char **value) { if (argc < 2 || argc > 3) { *path = NULL; *value = NULL; } if (argc == 2) { *path = "numbers.dict"; *value = argv[1]; } else { *path = argv[1]; *value = argv[2]; } } ================================================ FILE: rush02/ex00/srcs/ft/ft_file_load.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_tail.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/15 16:51:18 by asoursou #+# #+# */ /* Updated: 2019/07/20 23:15:40 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "ft.h" char *ft_file_read(int fd) { char buf[2048]; char *content; char *tmp; int len; int size; if (!(content = malloc(sizeof(char)))) return (NULL); *content = '\0'; size = 0; while ((len = read(fd, buf, 2048)) > 0) { if (!(tmp = malloc((size + len + 1) * sizeof(char)))) break ; tmp = ft_strncpy(tmp, content, size); free(content); ft_strncpy(tmp + size, buf, len); content = tmp; size += len; content[size] = '\0'; } if (len) free(content); return ((len) ? NULL : content); } char *ft_file_load(char *path) { char *content; int fd; fd = (path) ? open(path, O_RDONLY) : STDIN_FILENO; if (fd < 0) return (NULL); content = ft_file_read(fd); if (fd != STDIN_FILENO) close(fd); return (content); } ================================================ FILE: rush02/ex00/srcs/ft/ft_is_valid.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_is_valid.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hvernhes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 23:25:33 by hvernhes #+# #+# */ /* Updated: 2019/07/21 20:28:49 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_is_valid(char *value) { int n; int i; if (!*value) return (0); n = 0; i = -1; while (value[++i]) { if (value[i] < '0' || value[i] > '9') return (0); else if (n || value[i] != '0') n++; } return (n <= 12); } ================================================ FILE: rush02/ex00/srcs/ft/ft_isdigit.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_isdigit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hvernhes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 01:05:56 by hvernhes #+# #+# */ /* Updated: 2019/07/21 01:12:45 by hvernhes ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isdigit(char c) { return (c >= '0' && c <= '9'); } ================================================ FILE: rush02/ex00/srcs/ft/ft_isprint.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_isprint.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 01:30:49 by asoursou #+# #+# */ /* Updated: 2019/07/21 01:31:37 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isprint(char c) { return (c >= ' ' && c <= '~'); } ================================================ FILE: rush02/ex00/srcs/ft/ft_isspace.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_isspace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hvernhes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 01:09:33 by hvernhes #+# #+# */ /* Updated: 2019/07/21 01:13:59 by hvernhes ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isspace(char c) { return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' '); } ================================================ FILE: rush02/ex00/srcs/ft/ft_putchar.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/01 17:19:29 by asoursou #+# #+# */ /* Updated: 2019/07/02 17:28:36 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include void ft_putchar(char c) { write(1, &c, 1); } ================================================ FILE: rush02/ex00/srcs/ft/ft_putstr.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:00:11 by asoursou #+# #+# */ /* Updated: 2019/07/20 22:41:07 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" void ft_putstr(char *str) { write(1, str, ft_strlen(str)); } ================================================ FILE: rush02/ex00/srcs/ft/ft_strlen.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 03:11:19 by asoursou #+# #+# */ /* Updated: 2019/07/03 15:18:43 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int n; n = 0; while (str[n]) n++; return (n); } ================================================ FILE: rush02/ex00/srcs/ft/ft_strncpy.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 22:19:59 by asoursou #+# #+# */ /* Updated: 2019/07/16 22:20:01 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ char *ft_strncpy(char *dest, char *src, unsigned int n) { unsigned int i; i = -1; while (++i < n && src[i]) dest[i] = src[i]; while (i < n) dest[i++] = '\0'; return (dest); } ================================================ FILE: rush02/ex00/srcs/ft_dict/ft_dict_clear.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_dict_clear.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hvernhes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 02:24:34 by hvernhes #+# #+# */ /* Updated: 2019/07/21 02:53:57 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_dict.h" void ft_dict_clear(t_data *d) { free(d->name); free(d); } ================================================ FILE: rush02/ex00/srcs/ft_dict/ft_dict_cmp.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_dict_cmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 23:56:59 by asoursou #+# #+# */ /* Updated: 2019/07/21 00:19:14 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_dict.h" int ft_dict_cmp(t_data *d1, t_data *d2) { return (d1->value - d2->value); } ================================================ FILE: rush02/ex00/srcs/ft_dict/ft_dict_create.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_dict_create.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 00:48:04 by asoursou #+# #+# */ /* Updated: 2019/07/21 23:26:38 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" #include "ft_dict.h" t_list *ft_dicterr(t_list *l) { ft_list_clear(l, &ft_dict_clear); ft_putstr("Dict Error\n"); return (NULL); } int ft_is_valid_line(char *s, unsigned long *value, char **name) { long n; int i; i = 0; while (ft_isdigit(s[i])) i++; if (!i || i > 18 || (n = ft_atol(s)) < 0) return (0); *value = n; s += i; while (ft_isspace(*s)) s++; if (*s++ != ':') return (0); while (ft_isspace(*s)) s++; *name = s; i = 0; while (s[i] && s[i] != '\n') if (!ft_isprint(s[i])) return (0); else if (ft_isspace(s[i++])) while (ft_isspace(s[i])) s++; return (i && s[i] == '\n'); } t_list *ft_dict_check(t_list *dict) { unsigned int i; i = -1; while (++i < 10) if (!ft_dict_in(dict, i) || !ft_dict_in(dict, 10 + i) || !ft_dict_in(dict, 10 * i)) return (ft_dicterr(dict)); if (!ft_dict_in(dict, 100) || !ft_dict_in(dict, 1000) || !ft_dict_in(dict, 1000000) || !ft_dict_in(dict, 1000000)) return (ft_dicterr(dict)); return (dict); } t_list *ft_dict_create(char *content) { t_list *l; t_data *e; t_data t; l = NULL; while (*content) { if (*content == '\n') content++; else if (ft_is_valid_line(content, &t.value, &t.name) && !ft_list_find(l, &t, ft_dict_cmp) && (e = ft_dict_create_elem(t.value, t.name))) { ft_sorted_list_insert(&l, e, &ft_dict_cmp); while (*content != '\n') content++; } else return (ft_dicterr(l)); } return (ft_dict_check(l)); } ================================================ FILE: rush02/ex00/srcs/ft_dict/ft_dict_create_elem.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_dict_create_elem.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 00:56:44 by asoursou #+# #+# */ /* Updated: 2019/07/21 22:40:02 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" #include "ft_dict.h" int ft_dict_wordlen(char *s) { int i; i = 0; while (s[i] != '\n') if (ft_isspace(s[i++])) while (ft_isspace(s[i])) s++; return (i); } t_data *ft_dict_create_elem(unsigned long value, char *name) { t_data *d; int i; i = ft_dict_wordlen(name); if (!i || !(d = malloc(sizeof(t_data)))) return (NULL); d->value = value; if (!(d->name = malloc((i + 1) * sizeof(char)))) { free(d); return (NULL); } i = 0; while (*name != '\n') { d->name[i++] = (ft_isspace(*name)) ? ' ' : *name++; while (ft_isspace(*name) && *name != '\n') name++; } d->name[i] = '\0'; return (d); } ================================================ FILE: rush02/ex00/srcs/ft_dict/ft_dict_in.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_dict_in.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 10:34:11 by asoursou #+# #+# */ /* Updated: 2019/07/21 10:58:04 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_dict.h" t_data *ft_dict_in(t_list *dict, unsigned long value) { t_list *l; t_data d; d.value = value; return ((l = ft_list_find(dict, &d, &ft_dict_cmp)) ? l->data : NULL); } ================================================ FILE: rush02/ex00/srcs/ft_dict/ft_print.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hvernhes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/21 00:53:28 by hvernhes #+# #+# */ /* Updated: 2019/07/21 23:08:01 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft.h" #include "ft_dict.h" void ft_putvalue(t_list *dict, unsigned long n, int count) { if (count) ft_putchar(' '); ft_putstr(ft_dict_in(dict, n)->name); } int ft_special(t_list *dict, unsigned long n, int count) { unsigned long i; i = 1000000000000; while ((i /= 1000) >= 1000) if (i == n) return (0); if (n == 100 || !ft_dict_in(dict, n)) return (0); ft_putvalue(dict, n, count); return (1); } int ft_print_digits(t_list *dict, unsigned long n, int count) { if ((n %= 1000) >= 100) { ft_putvalue(dict, n / 100, count++); ft_putvalue(dict, 100, count); if (n == 100) return (count); } if (ft_dict_in(dict, (n %= 100))) ft_putvalue(dict, n, count++); else { if (n >= 10) ft_putvalue(dict, (n / 10) * 10, count++); if ((n %= 10)) ft_putvalue(dict, n, count++); } return (count); } void ft_print(t_list *dict, char *value) { unsigned long n; unsigned long mask; int count; while (*value == '0' && *(value + 1)) value++; mask = 1000000000; count = 0; while (*value) { if (ft_special(dict, (n = ft_atol(value)), count)) break ; while (mask > n + 1) mask /= 1000; count = ft_print_digits(dict, n / mask, count); if (mask > 1) ft_putvalue(dict, mask, count++); n = ft_strlen(value); value++; while (ft_strlen(value) % 3) value++; while (*value == '0') value++; } ft_putchar('\n'); } ================================================ FILE: rush02/ex00/srcs/ft_list/ft_create_elem.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_create_elem.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 01:38:16 by asoursou #+# #+# */ /* Updated: 2019/07/18 02:17:18 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" t_list *ft_create_elem(void *data) { t_list *l; if (!(l = malloc(sizeof(t_list)))) return (NULL); l->next = NULL; l->data = data; return (l); } ================================================ FILE: rush02/ex00/srcs/ft_list/ft_list_clear.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_clear.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/18 18:15:02 by asoursou #+# #+# */ /* Updated: 2019/07/21 02:58:36 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft_list.h" void ft_list_clear(t_list *begin_list, void (*free_fct)()) { if (!begin_list) return ; ft_list_clear(begin_list->next, free_fct); if (free_fct) free_fct(begin_list->data); free(begin_list); } ================================================ FILE: rush02/ex00/srcs/ft_list/ft_list_find.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_find.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 02:44:24 by asoursou #+# #+# */ /* Updated: 2019/07/19 03:03:00 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()) { if (!begin_list || !cmp(begin_list->data, data_ref)) return (begin_list); return (ft_list_find(begin_list->next, data_ref, cmp)); } ================================================ FILE: rush02/ex00/srcs/ft_list/ft_sorted_list_insert.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sorted_list_insert.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/20 03:43:01 by asoursou #+# #+# */ /* Updated: 2019/07/20 04:26:57 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)()) { t_list *e; if (!*begin_list || cmp(data, (*begin_list)->data) <= 0) { if (!(e = ft_create_elem(data))) return ; e->next = *begin_list; *begin_list = e; } else ft_sorted_list_insert(&(*begin_list)->next, data, cmp); } ================================================ FILE: rush02/ex00/srcs/main.c ================================================ /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: asoursou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/12 15:32:28 by asoursou #+# #+# */ /* Updated: 2019/07/21 23:16:48 by asoursou ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "ft.h" #include "ft_dict.h" int main(int argc, char **argv) { t_list *dict; char *path; char *value; char *content; ft_check_args(argc, argv, &path, &value); if (!ft_is_valid(value)) ft_putstr("Error\n"); else if ((content = ft_file_load(path))) { dict = ft_dict_create(content); free(content); if (dict) { ft_print(dict, value); ft_list_clear(dict, &ft_dict_clear); } } else ft_putstr("Dict Error\n"); return (0); } ================================================ FILE: rush02/ex00/test.sh ================================================ #!/bin/bash if [ "$#" != "1" ]; then echo "error: Invalid argument" exit fi n=$1 while [ "$n" -ge "0" ]; do ./rush-02 $n n=`expr "$n" - 1`; done ================================================ FILE: shell00/ex00/z ================================================ Z ================================================ FILE: shell00/ex03/klist.txt ================================================ Credentials cache: API:597EA158-C46F-4F28-9226-87F55BEEEF86 Principal: asoursou@42.FR Issued Expires Principal Jul 1 08:56:05 2019 Jul 8 08:56:05 2019 krbtgt/42.FR@42.FR Jul 1 09:46:20 2019 Jul 8 08:56:05 2019 host/vgs-fn1.42.fr@42.FR ================================================ FILE: shell00/ex04/midLS ================================================ #!/bin/sh ls -mUtp ================================================ FILE: shell00/ex05/git_commit.sh ================================================ #!/bin/sh git log -5 --pretty=%H ================================================ FILE: shell00/ex06/git_ignore.sh ================================================ #!/bin/sh git status -s --ignored | grep '!!' | sed 's/!! //' ================================================ FILE: shell00/ex07/b ================================================ 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.. ================================================ FILE: shell00/ex08/clean ================================================ #!/bin/sh find . -type f \( -name '*~' -o -name '#*#' \) -print -delete ================================================ FILE: shell00/ex09/ft_magic ================================================ 42 string 42 42 file ================================================ FILE: shell01/ex01/print_groups.sh ================================================ #!/bin/sh groups $FT_USER | tr ' ' ',' | tr -d '\n' ================================================ FILE: shell01/ex02/find_sh.sh ================================================ #!/bin/sh find . -type f -name '*.sh' | sed 's/.*\///' | sed 's/...$//' ================================================ FILE: shell01/ex03/count_files.sh ================================================ #!/bin/sh find . -type f -o -type d | wc -l | tr -d ' ' ================================================ FILE: shell01/ex04/MAC.sh ================================================ #!/bin/sh ifconfig -a | grep ether | cut -c 8-24 ================================================ FILE: shell01/ex05/"/?$*'MaRViN'*$?/" ================================================ 42 ================================================ FILE: shell01/ex06/skip.sh ================================================ #!/bin/bash ls -l | awk 'NR%2' ================================================ FILE: shell01/ex07/r_dwssap.sh ================================================ #!/bin/sh cat /etc/passwd | grep -v '#' | awk 'NR%2==0' | cut -d : -f 1 | rev | sort -r | awk "NR>=$FT_LINE1 && NR<=$FT_LINE2" | tr '\n' ' ' | sed '$ s/ $/./' | sed 's/ /, /g' | tr -d '\n' ================================================ FILE: shell01/ex08/add_chelou.sh ================================================ #!/bin/sh n1=`echo $FT_NBR1 | sed 'y/'\''\\"?!/01234/'` n2=`echo $FT_NBR2 | sed 'y/mrdoc/01234/'` b5=`echo "ibase=5;$n1+$n2" | bc` echo "obase=13;$b5" | bc | sed 'y/0123456789ABC/gtaio luSnemf/'