Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* main.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: daron <marvin@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2019/08/18 13:52:30 by daron #+# #+# */
- /* Updated: 2019/08/18 17:17:28 by daron ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "ft_list.h"
- #include <stdlib.h>
- void ft_putstr(char *str)
- {
- int i;
- i = 0;
- while (str[i] != '\0')
- write(1, &str, 1);
- }
- t_list *read_buf()
- {
- t_list *ptr;
- char c;
- ptr = NULL;
- while (read(0, &c, 1) > 0)
- ft_list_push_back(&ptr, c);
- return (ptr);
- }
- void ft_check_size(t_list *ptrr,int *width, int *height)
- {
- int h;
- int w;
- int f;
- t_list *ptr;
- f = 1;
- h = 0;
- w = 0;
- ptr = ptrr;
- while (ptr->next)
- {
- if (ptr->c == '\n' || ptr->c == '\0')
- {
- h++;
- f = 0;
- }
- if (f)
- w++;
- ptr = ptr->next;
- }
- *width = w;
- *height = h + 1;
- }
- /*int ft_check_squareness(t_list *ptrr, int weight)
- {
- int i;
- t_list *ptr;
- ptr = ptrr;
- while(ptr)
- {
- i = 0;
- if (ptr->c != '\n')
- i++;
- else if (i != (weight - 1))
- return (1);
- ptr = ptr->next;
- }
- return (0);
- }*/
- int check_place(int i, int j, int weight, int height)
- {
- if (i == 0 && j == 0)
- return (0);//Верхнией левый угол
- else if (i == 0 && j == (weight - 1))
- return (1);
- else if (j == (weight - 1) && i == (height - 1))
- return (2);
- else if (i == (height - 1) && j == 0)
- return (3);
- else if (i == 0 && j > 0 && j < (weight - 1))
- return (4);
- else if (j == (weight - 1) && i > 0 && i < (height - 1))
- return (5);
- else if (i == (height - 1) && j > 0 && j < (weight - 1))
- return (6);
- else if (j == 0 && i > 0 && i < (height - 1))
- return (7);
- return (-1) ;
- }
- void ft_check_rush(t_list *ptr, int weigth, int height)
- {
- int i;
- int j;
- i = 0;
- while (i < height)
- {
- j = 0;
- while (j < weigth && ptr)
- {
- printf("%c%d\n", ptr->c, check_place(i, j, weigth, height));
- j++;
- ptr = ptr->next;
- }
- i++;
- }
- }
- int ft_rush00()
- int main(void)
- {
- t_list *ptr;
- int height = 0;
- int width = 0;
- ptr = read_buf();
- /*while (ptr->next)
- {
- printf("%c", ptr->c);
- ptr = ptr->next;
- }*/
- ft_check_size(ptr, &width, &height);
- printf("%d %d\n", width, height);
- ft_check_rush(ptr, width, height);
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement