Guest User

Untitled

a guest
Oct 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include "fillit.h"
  2.  
  3. void ft_error(void)
  4. {
  5. ft_putstr("error\n");
  6. exit(0);
  7. }
  8.  
  9. t_tetri *ft_fill(char *str)
  10. {
  11. size_t i;
  12. size_t j;
  13. char c;
  14. t_tetri *block;
  15. t_tetri *tmp;
  16.  
  17. j = 0;
  18. c = 64;
  19. i = 0;
  20. i = ft_valid_check(str, i);
  21. if (!(block = (t_tetri *)malloc(sizeof(t_tetri))))
  22. return (NULL);
  23. tmp = block;
  24. while (i-- > 0)
  25. {
  26. tmp->str = ft_strndup(&str[j], 20);
  27. ft_plus_check(tmp->str);
  28. tmp->c = ++c;
  29. j += 21;
  30. if (!(tmp->next = (t_tetri *)malloc(sizeof(t_tetri))))
  31. return (NULL);
  32. tmp = tmp->next;
  33. }
  34. tmp->next = NULL;
  35. return (block);
  36. }
  37.  
  38. char *ft_read(char *file)
  39. {
  40. int fd;
  41. size_t i;
  42. char tmp[545];
  43. char buffer[1];
  44.  
  45. i = 0;
  46. if ((fd = open(file, O_RDONLY)) == -1)
  47. ft_error();
  48. while (read(fd, buffer, 1))
  49. {
  50. tmp[i++] = buffer[0];
  51. if (i > 545)
  52. ft_error();
  53. }
  54. tmp[i] = '\0';
  55. if (close(fd) == -1)
  56. ft_error();
  57. return (ft_strdup(tmp));
  58. }
  59.  
  60. int main(int argc, char **argv)
  61. {
  62. t_tetri *list;
  63. char *str;
  64. char **final;
  65. int max;
  66.  
  67. max = 2;
  68. if (argc != 2)
  69. {
  70. ft_putstr("usage: chemin de fichier !!\n");
  71. exit(0);
  72. }
  73. str = ft_read(argv[1]);
  74. list = ft_fill(str);
  75. list = ft_filling_xy(list);
  76. final = ft_result(list, max);
  77. while (*final)
  78. ft_putendl(*final++);
  79. return (0);
  80. }
Add Comment
Please, Sign In to add comment