Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "libft.h"
- void ft_display(int num, int x, int y, int multi)
- {
- ft_putstr("[colle-0");
- ft_putchar(num + 48);
- ft_putstr("] [");
- ft_putnbr(x);
- ft_putstr("] [");
- ft_putnbr(y);
- if (multi == 1)
- ft_putstr("] || ");
- else
- ft_putstr("]\n");
- }
- void ft_select(char *str)
- {
- int x;
- int y;
- x = ft_x_len(str);
- y = ft_y_high(str);
- if (str[0] == '/')
- {
- if (ft_strcmp(str, rush01(x, y)) == 0)
- ft_display(1, x, y, 0);
- }
- else if (str[0] == 'o')
- {
- if (ft_strcmp(str, rush00(x, y)) == 0)
- ft_display(0, x, y, 0);
- }
- else
- ft_putstr("aucune\n");
- }
- void ft_select_colle(char *str)
- {
- int x;
- int y;
- x = ft_x_len(str);
- y = ft_y_high(str);
- if (str[0] == 'A')
- {
- if (ft_strcmp(str, rush02(x, y)) == 0 && (x > 1 || y > 1))
- ft_display(2, x, y, 0);
- else if (ft_strcmp(str, rush03(x, y)) == 0 && (x > 1 || y > 1))
- ft_display(3, x, y, 0);
- else if (ft_strcmp(str, rush04(x, y)) == 0 && (x > 1 || y > 1))
- ft_display(4, x, y, 0);
- else
- {
- ft_display(2, x, y, 1);
- ft_display(3, x, y, 1);
- ft_display(4, x, y, 0);
- }
- }
- else
- ft_select(str);
- }
- char *get_rectangle(void)
- {
- char *rect;
- int ret;
- int i;
- i = 0;
- rect = (char*)malloc(sizeof(char*) * BUF_SIZE);
- ret = read(0, rect, BUF_SIZE);
- if (ft_x_len(rect) < 1 || ft_y_high(rect) < 1 || rect[0] == '\0')
- {
- ft_putstr("aucune\n");
- return (0);
- }
- ft_select_colle(rect);
- return (rect);
- }
- int main(void)
- {
- get_rectangle();
- return (0);
- }
- ????????????????????????????????????????????????????????????????????????????
- #include <unistd.h>
- void ft_putchar(char c)
- {
- write(1, &c, 1);
- }
- void ft_putstr(char *str)
- {
- int i;
- i = 0;
- while (str[i] != '\0')
- {
- ft_putchar(str[i]);
- i++;
- }
- }
- void ft_putnbr(int nb)
- {
- if (nb > 9)
- {
- ft_putnbr(nb / 10);
- ft_putchar(nb % 10 + 48);
- }
- else
- ft_putchar(nb + 48);
- }
- int ft_strcmp(char *s1, char *s2)
- {
- int i;
- i = 0;
- while (s1[i] || s2[i])
- {
- if (s1[i] != s2[i])
- return (s1[i] - s2[i]);
- i++;
- }
- return (0);
- }
- int ft_x_len(char *str)
- {
- int i;
- i = 0;
- while (str[i] != '\n')
- {
- i++;
- }
- return (i);
- }
- int ft_y_high(char *str)
- {
- int i;
- int j;
- i = 0;
- j = 0;
- while (str[i] != '\0')
- {
- if (str[i] == '\n')
- j++;
- i++;
- }
- return (j);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement