Advertisement
Guest User

ficher 2

a guest
Dec 15th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.43 KB | None | 0 0
  1. /*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  2. ** EPITECH PROJECT, 2019                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  3. ** func_1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  4. ** File description:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
  5. ** func 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  6. */
  7.  
  8. #include <ncurses.h>
  9. #include "my.h"
  10. #include <unistd.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>
  16.  
  17. #define L KEY_LEFT
  18. #define R KEY_RIGHT
  19. #define U KEY_UP
  20. #define D KEY_DOWN
  21. #define S 32
  22. #define E 27
  23.  
  24. char **my_malloc(char *buf, number *nb)
  25. {
  26.     int col = 0;
  27.  
  28.     nb->line = 0;
  29.     for (col = 0; buf[col] != '\0';col++) {
  30.         if (buf[col] == '\n')
  31.             nb->line++;
  32.     }
  33.     nb->line++;
  34.     col = (col - nb->line) / nb->line;
  35.     return (mem_alloc_2d_array(nb->line, col));
  36. }
  37.  
  38. void copie(char *buf, char **map, number *nb)
  39. {
  40.     int j = 0;
  41.     int n = 0;
  42.  
  43.     for (int i = 0; buf[i] != '\0'; i++) {
  44.         while (buf[i] != '\n' && buf[i] != '\0') {
  45.             if (buf[i] == 'P') {
  46.                 buf[i] = ' ';
  47.                 nb->x = n;
  48.                 nb->y = j;
  49.                 nb->x_bis = n;
  50.                 nb->y_bis = j;
  51.             }
  52.             map[j][n] = buf[i];
  53.             n++;
  54.             i++;
  55.         }
  56.         map[j][n] = buf[i];
  57.         j++;
  58.         n = 0;
  59.     }
  60. }
  61.  
  62. void print_(char **map, number *nb)
  63. {
  64.     while (map[nb->i]) {
  65.         mvprintw(nb->middle_y, nb->middle_x, map[nb->i]);
  66.         nb->i++;
  67.         nb->middle_y++;
  68.     }
  69.     if (nb->l != 1) {
  70.         nb->y += (nb->max_y / 2);
  71.         nb->x += (nb->max_x / 2);
  72.         nb->l++;
  73.     }
  74.     mvprintw(nb->y, nb->x, "P");
  75. }
  76.  
  77. unsigned int stat_file(char const *filepath)
  78. {
  79.     struct stat sb;
  80.  
  81.     stat(filepath, &sb);
  82.     return (sb.st_size);
  83. }
  84.  
  85. void desc(char **av)
  86. {
  87.     int fs = open("des", O_RDONLY);
  88.     int size = stat_file("des");
  89.     char *buf = malloc(sizeof(char) * (size + 1));
  90.     int fd = read(fs, buf, size);
  91.  
  92.     write(1, buf, size);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement