Advertisement
Guest User

lfg

a guest
Aug 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include "libft.h"
  5.  
  6. void ft_display(int num, int x, int y, int multi)
  7. {
  8. ft_putstr("[colle-0");
  9. ft_putchar(num + 48);
  10. ft_putstr("] [");
  11. ft_putnbr(x);
  12. ft_putstr("] [");
  13. ft_putnbr(y);
  14. if (multi == 1)
  15. ft_putstr("] || ");
  16. else
  17. ft_putstr("]\n");
  18. }
  19.  
  20. void ft_select(char *str)
  21. {
  22. int x;
  23. int y;
  24.  
  25. x = ft_x_len(str);
  26. y = ft_y_high(str);
  27. if (str[0] == '/')
  28. {
  29. if (ft_strcmp(str, rush01(x, y)) == 0)
  30. ft_display(1, x, y, 0);
  31. }
  32. else if (str[0] == 'o')
  33. {
  34. if (ft_strcmp(str, rush00(x, y)) == 0)
  35. ft_display(0, x, y, 0);
  36. }
  37. else
  38. ft_putstr("aucune\n");
  39. }
  40.  
  41. void ft_select_colle(char *str)
  42. {
  43. int x;
  44. int y;
  45.  
  46. x = ft_x_len(str);
  47. y = ft_y_high(str);
  48. if (str[0] == 'A')
  49. {
  50. if (ft_strcmp(str, rush02(x, y)) == 0 && (x > 1 || y > 1))
  51. ft_display(2, x, y, 0);
  52. else if (ft_strcmp(str, rush03(x, y)) == 0 && (x > 1 || y > 1))
  53. ft_display(3, x, y, 0);
  54. else if (ft_strcmp(str, rush04(x, y)) == 0 && (x > 1 || y > 1))
  55. ft_display(4, x, y, 0);
  56. else
  57. {
  58. ft_display(2, x, y, 1);
  59. ft_display(3, x, y, 1);
  60. ft_display(4, x, y, 0);
  61. }
  62. }
  63. else
  64. ft_select(str);
  65. }
  66.  
  67. char *get_rectangle(void)
  68. {
  69. char *rect;
  70. int ret;
  71. int i;
  72.  
  73. i = 0;
  74. rect = (char*)malloc(sizeof(char*) * BUF_SIZE);
  75. ret = read(0, rect, BUF_SIZE);
  76. if (ft_x_len(rect) < 1 || ft_y_high(rect) < 1 || rect[0] == '\0')
  77. {
  78. ft_putstr("aucune\n");
  79. return (0);
  80. }
  81. ft_select_colle(rect);
  82. return (rect);
  83. }
  84.  
  85. int main(void)
  86. {
  87. get_rectangle();
  88. return (0);
  89. }
  90.  
  91.  
  92. ????????????????????????????????????????????????????????????????????????????
  93. #include <unistd.h>
  94.  
  95. void ft_putchar(char c)
  96. {
  97. write(1, &c, 1);
  98. }
  99.  
  100. void ft_putstr(char *str)
  101. {
  102. int i;
  103.  
  104. i = 0;
  105. while (str[i] != '\0')
  106. {
  107. ft_putchar(str[i]);
  108. i++;
  109. }
  110. }
  111.  
  112. void ft_putnbr(int nb)
  113. {
  114. if (nb > 9)
  115. {
  116. ft_putnbr(nb / 10);
  117. ft_putchar(nb % 10 + 48);
  118. }
  119. else
  120. ft_putchar(nb + 48);
  121. }
  122.  
  123. int ft_strcmp(char *s1, char *s2)
  124. {
  125. int i;
  126.  
  127. i = 0;
  128. while (s1[i] || s2[i])
  129. {
  130. if (s1[i] != s2[i])
  131. return (s1[i] - s2[i]);
  132. i++;
  133. }
  134. return (0);
  135. }
  136. int ft_x_len(char *str)
  137. {
  138. int i;
  139.  
  140. i = 0;
  141. while (str[i] != '\n')
  142. {
  143. i++;
  144. }
  145. return (i);
  146. }
  147.  
  148. int ft_y_high(char *str)
  149. {
  150. int i;
  151. int j;
  152.  
  153. i = 0;
  154. j = 0;
  155. while (str[i] != '\0')
  156. {
  157. if (str[i] == '\n')
  158. j++;
  159. i++;
  160. }
  161. return (j);
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement