sakiir

test

Oct 25th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. /*
  2. ** main.c for colle3 in /home/dupard_e/rendus/Piscine_C_colles-Semaine_03
  3. **
  4. ** Made by Erwan Dupard
  5. ** Login   <[email protected]>
  6. **
  7. ** Started on  Sat Oct 25 14:07:34 2014 Erwan Dupard
  8. ** Last update Sat Oct 25 18:17:30 2014 Erwan Dupard
  9. */
  10.  
  11. #include "my_struct.h"
  12.  
  13. int     main(int argc, char **argv)
  14. {
  15.   char      buff[BUFF_SIZE + 1];
  16.   int       len;
  17.  
  18.   while ((len = read(0, buff, BUFF_SIZE)) != 0)
  19.     {
  20.       printf("%d\n", len);
  21.       detect(buff);
  22.       //printf("x : %d && y : %d\n", get_x(buff), get_y(buff));
  23.     }
  24.   return (0);
  25. }
  26.  
  27. int     get_x(char *str)
  28. {
  29.   int       x;
  30.   int       i;
  31.  
  32.   x = 0;
  33.   i = 0;
  34.   while (str[i] != '\n')
  35.     {
  36.       x++;
  37.       i++;
  38.     }
  39.   return (x);
  40. }
  41.  
  42. int     get_y(char *str)
  43. {
  44.   int       y;
  45.  
  46.   y = 0;
  47.   while (*str != 0)
  48.     {
  49.       if (*str == '\n')
  50.     y++;
  51.       str++;
  52.     }
  53.   return (y);
  54. }
  55.  
  56. void            detect(char *str)
  57. {
  58.   int       x;
  59.   int       y;
  60.   char      *colle;
  61.  
  62.   x = get_x(str);
  63.   y = get_y(str);
  64.  
  65.   if (*str == 'o')
  66.     colle = my_strdup("[colle1-1]");
  67.   if (*str == '/')
  68.     colle = my_strdup("[colle1-2]");
  69.   printf("%s %d %d\n", colle, x, y);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment