├── inter ├── subject.en.txt └── inter.c ├── union ├── subject.en.txt └── union.c ├── get_next_line.c └── ft_printf.c /inter/subject.en.txt: -------------------------------------------------------------------------------- 1 | Assignment name : inter 2 | Expected files : inter.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that takes two strings and displays, without doubles, the 7 | characters that appear in both strings, in the order they appear in the first 8 | one. 9 | 10 | The display will be followed by a \n. 11 | 12 | If the number of arguments is not 2, the program displays \n. 13 | 14 | Examples: 15 | 16 | $>./inter "padinton" "paqefwtdjetyiytjneytjoeyjnejeyj" | cat -e 17 | padinto$ 18 | $>./inter ddf6vewg64f gtwthgdwthdwfteewhrtag6h4ffdhsd | cat -e 19 | df6ewg4$ 20 | $>./inter "rien" "cette phrase ne cache rien" | cat -e 21 | rien$ 22 | $>./inter | cat -e 23 | $ 24 | -------------------------------------------------------------------------------- /union/subject.en.txt: -------------------------------------------------------------------------------- 1 | Assignment name : union 2 | Expected files : union.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that takes two strings and displays, without doubles, the 7 | characters that appear in either one of the strings. 8 | 9 | The display will be in the order characters appear in the command line, and 10 | will be followed by a \n. 11 | 12 | If the number of arguments is not 2, the program displays \n. 13 | 14 | Example: 15 | 16 | $>./union zpadinton "paqefwtdjetyiytjneytjoeyjnejeyj" | cat -e 17 | zpadintoqefwjy$ 18 | $>./union ddf6vewg64f gtwthgdwthdwfteewhrtag6h4ffdhsd | cat -e 19 | df6vewg4thras$ 20 | $>./union "rien" "cette phrase ne cache rien" | cat -e 21 | rienct phas$ 22 | $>./union | cat -e 23 | $ 24 | $> 25 | $>./union "rien" | cat -e 26 | $ 27 | $> 28 | -------------------------------------------------------------------------------- /inter/inter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* inter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ajaidi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/22 10:03:37 by ajaidi #+# #+# */ 9 | /* Updated: 2021/12/22 10:05:38 by ajaidi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | char map[255]; 19 | int i; 20 | int j; 21 | 22 | i = -1; 23 | if (argc == 3) 24 | { 25 | while (argv[1][++i]) 26 | { 27 | j = -1; 28 | while (argv[2][++j]) 29 | { 30 | if (map[argv[1][i]] != 1 && (argv[1][i] == argv[2][j])) 31 | { 32 | write(1, &argv[1][i], 1); 33 | map[argv[1][i]] = 1; 34 | } 35 | } 36 | } 37 | } 38 | write(1, "\n", 1); 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /union/union.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* union.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ajaidi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/22 10:07:53 by ajaidi #+# #+# */ 9 | /* Updated: 2021/12/22 10:07:54 by ajaidi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | char map[255]; 18 | int i; 19 | 20 | i = -1; 21 | if (argc == 3) 22 | { 23 | while (argv[1][++i]) 24 | { 25 | if (map[argv[1][i]] != 1) 26 | { 27 | write(1, &argv[1][i], 1); 28 | map[argv[1][i]] = 1; 29 | } 30 | } 31 | i = -1; 32 | while (argv[2][++i]) 33 | { 34 | if (map[argv[2][i]] != 1) 35 | { 36 | write(1, &argv[2][i], 1); 37 | map[argv[2][i]] = 1; 38 | } 39 | } 40 | } 41 | write(1, "\n", 1); 42 | } 43 | -------------------------------------------------------------------------------- /get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ajaidi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/21 21:33:43 by ajaidi #+# #+# */ 9 | /* Updated: 2021/12/21 22:31:48 by ajaidi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (str[i]) 19 | i++; 20 | return (i); 21 | } 22 | 23 | char *ft_strdup(char *str) 24 | { 25 | int len; 26 | int i; 27 | char *dup; 28 | 29 | len = ft_strlen(str); 30 | i = -1; 31 | dup = malloc(len + 1); 32 | if (!dup) 33 | return (NULL); 34 | while (str[++i]) 35 | dup[i] = str[i]; 36 | dup[i] = 0; 37 | return (dup); 38 | } 39 | 40 | char *get_next_line(int fd) 41 | { 42 | char buffer; 43 | char rtn[7000000]; 44 | int n; 45 | int i; 46 | 47 | if (fd < 0 || BUFFER_SIZE <= 0) 48 | return (0); 49 | i = 0; 50 | n = read(fd, &buffer, 1); 51 | while (n > 0) 52 | { 53 | rtn[i++] = buffer; 54 | if (buffer == '\n') 55 | break ; 56 | n = read(fd, &buffer, 1); 57 | } 58 | rtn[i] = 0; 59 | if (n <= 0 && i == 0) 60 | return (0); 61 | return (ft_strdup(rtn)); 62 | } 63 | -------------------------------------------------------------------------------- /ft_printf.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ajaidi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/23 17:52:09 by ajaidi #+# #+# */ 9 | /* Updated: 2021/12/24 19:35:13 by ajaidi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_putchar(char c) 17 | { 18 | write(1, &c, 1); 19 | return (1); 20 | } 21 | 22 | int ft_putstr(char *str) 23 | { 24 | int len; 25 | 26 | len = 0; 27 | if (!str) 28 | str = "(null)"; 29 | while (*str) 30 | len += write(1, str++, 1); 31 | return (len); 32 | } 33 | 34 | int ft_putnbr(int nb) 35 | { 36 | long long n; 37 | int len; 38 | 39 | len = 0; 40 | n = nb; 41 | if (n < 0) 42 | { 43 | len += write(1, "-", 1); 44 | n = -n; 45 | } 46 | if (n > 9) 47 | { 48 | len += ft_putnbr(n / 10); 49 | len += ft_putnbr(n % 10); 50 | } 51 | else 52 | len += ft_putchar(n + 48); 53 | return (len); 54 | } 55 | 56 | int ft_puthex(unsigned int n) 57 | { 58 | int len; 59 | 60 | len = 0; 61 | if (n > 15) 62 | { 63 | len += ft_puthex(n / 16); 64 | len += ft_puthex(n % 16); 65 | } 66 | else if (n > 9) 67 | len += ft_putchar(n + 87); 68 | else 69 | len += ft_putchar(n + 48); 70 | return (len); 71 | } 72 | 73 | int ft_printf(const char *format, ...) 74 | { 75 | int i; 76 | int len; 77 | va_list ptr; 78 | 79 | len = 0; 80 | i = -1; 81 | va_start(ptr, format); 82 | while (format[++i]) 83 | { 84 | if (format[i] != '%') 85 | len += write(1, &format[i], 1); 86 | else if (format[i] == '%' && format[i + 1]) 87 | { 88 | i++; 89 | if (format[i] == 's') 90 | len += ft_putstr(va_arg(ptr, char *)); 91 | else if (format[i] == 'x') 92 | len += ft_puthex(va_arg(ptr, unsigned int)); 93 | else if (format[i] == 'd') 94 | len += ft_putnbr(va_arg(ptr, int)); 95 | } 96 | } 97 | va_end(ptr); 98 | return (len); 99 | } 100 | --------------------------------------------------------------------------------