Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. /* ************************************************************************** */
  2. /*                                                                            */
  3. /*                                                        :::      ::::::::   */
  4. /*   main.c                                             :+:      :+:    :+:   */
  5. /*                                                    +:+ +:+         +:+     */
  6. /*   By: daron <marvin@42.fr>                       +#+  +:+       +#+        */
  7. /*                                                +#+#+#+#+#+   +#+           */
  8. /*   Created: 2019/08/18 13:52:30 by daron             #+#    #+#             */
  9. /*   Updated: 2019/08/18 17:17:28 by daron            ###   ########.fr       */
  10. /*                                                                            */
  11. /* ************************************************************************** */
  12.  
  13. #include "ft_list.h"
  14. #include <stdlib.h>
  15.  
  16. void ft_putstr(char *str)
  17. {
  18.     int i;
  19.  
  20.     i = 0;
  21.     while (str[i] != '\0')
  22.         write(1, &str, 1);
  23. }
  24.  
  25. t_list *read_buf()
  26. {
  27.     t_list *ptr;
  28.     char c;
  29.  
  30.     ptr = NULL;
  31.     while (read(0, &c, 1) > 0)
  32.         ft_list_push_back(&ptr, c);
  33.     return (ptr);
  34. }
  35.  
  36. void ft_check_size(t_list *ptrr,int *width, int *height)
  37. {
  38.     int h;
  39.     int w;
  40.     int f;
  41.     t_list *ptr;
  42.  
  43.     f = 1;
  44.     h = 0;
  45.     w = 0;
  46.     ptr = ptrr;
  47.     while (ptr->next)
  48.     {
  49.         if (ptr->c == '\n' || ptr->c == '\0')
  50.         {
  51.             h++;
  52.             f = 0;
  53.         }
  54.         if (f)
  55.             w++;
  56.         ptr = ptr->next;
  57.     }  
  58.     *width = w;
  59.     *height = h + 1;
  60. }
  61.  
  62. /*int ft_check_squareness(t_list *ptrr, int weight)
  63. {
  64.     int i;
  65.     t_list *ptr;
  66.  
  67.     ptr = ptrr;
  68.     while(ptr)
  69.     {
  70.         i = 0;
  71.         if (ptr->c != '\n')
  72.             i++;
  73.         else if (i != (weight - 1))
  74.             return (1);
  75.         ptr = ptr->next;
  76.     }
  77.     return (0);
  78. }*/
  79.  
  80. int check_place(int i, int j, int weight, int height)
  81. {
  82.     if (i == 0 && j == 0)
  83.         return (0);//Верхнией левый угол
  84.     else if (i == 0 && j == (weight - 1))
  85.         return (1);
  86.     else if (j == (weight - 1) && i == (height - 1))
  87.         return (2);
  88.     else if (i == (height - 1) && j == 0)
  89.         return (3);
  90.     else if (i == 0 && j > 0 && j < (weight - 1))
  91.        return (4);
  92.     else if (j == (weight - 1) && i > 0 && i < (height - 1))
  93.         return (5);
  94.     else if (i == (height - 1) && j > 0 && j < (weight - 1))
  95.         return (6);
  96.     else if (j == 0 && i > 0  && i < (height - 1))
  97.         return (7);
  98.     return (-1) ;
  99. }
  100.  
  101. void ft_check_rush(t_list *ptr, int weigth, int height)
  102. {
  103.     int i;
  104.     int j;
  105.  
  106.     i = 0;
  107.     while (i < height)
  108.     {
  109.         j = 0; 
  110.         while (j < weigth && ptr)
  111.         {
  112.             printf("%c%d\n", ptr->c, check_place(i, j, weigth, height));
  113.             j++;
  114.             ptr = ptr->next;
  115.         }
  116.         i++;
  117.     }  
  118. }  
  119.  
  120. int ft_rush00()
  121.  
  122. int main(void)
  123. {
  124.     t_list *ptr;
  125.     int height = 0;
  126.     int width = 0;
  127.  
  128.     ptr = read_buf();
  129.     /*while (ptr->next)
  130.     {
  131.         printf("%c", ptr->c);
  132.         ptr = ptr->next;
  133.     }*/
  134.     ft_check_size(ptr, &width, &height);
  135.     printf("%d %d\n", width, height);
  136.    
  137.     ft_check_rush(ptr, width, height);
  138.  
  139.     return (0);
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement