Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "fillit.h"
- void ft_error(void)
- {
- ft_putstr("error\n");
- exit(0);
- }
- t_tetri *ft_fill(char *str)
- {
- size_t i;
- size_t j;
- char c;
- t_tetri *block;
- t_tetri *tmp;
- j = 0;
- c = 64;
- i = 0;
- i = ft_valid_check(str, i);
- if (!(block = (t_tetri *)malloc(sizeof(t_tetri))))
- return (NULL);
- tmp = block;
- while (i-- > 0)
- {
- tmp->str = ft_strndup(&str[j], 20);
- ft_plus_check(tmp->str);
- tmp->c = ++c;
- j += 21;
- if (!(tmp->next = (t_tetri *)malloc(sizeof(t_tetri))))
- return (NULL);
- tmp = tmp->next;
- }
- tmp->next = NULL;
- return (block);
- }
- char *ft_read(char *file)
- {
- int fd;
- size_t i;
- char tmp[545];
- char buffer[1];
- i = 0;
- if ((fd = open(file, O_RDONLY)) == -1)
- ft_error();
- while (read(fd, buffer, 1))
- {
- tmp[i++] = buffer[0];
- if (i > 545)
- ft_error();
- }
- tmp[i] = '\0';
- if (close(fd) == -1)
- ft_error();
- return (ft_strdup(tmp));
- }
- int main(int argc, char **argv)
- {
- t_tetri *list;
- char *str;
- char **final;
- int max;
- max = 2;
- if (argc != 2)
- {
- ft_putstr("usage: chemin de fichier !!\n");
- exit(0);
- }
- str = ft_read(argv[1]);
- list = ft_fill(str);
- list = ft_filling_xy(list);
- final = ft_result(list, max);
- while (*final)
- ft_putendl(*final++);
- return (0);
- }
Add Comment
Please, Sign In to add comment