eg0rmaffin

test

Jul 14th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.85 KB | None | 0 0
  1. /* ************************************************************************** */
  2. /*                                                                            */
  3. /*                                                        :::      ::::::::   */
  4. /*   test.c                                             :+:      :+:    :+:   */
  5. /*                                                    +:+ +:+         +:+     */
  6. /*   By: squiana <[email protected]>                     +#+  +:+       +#+        */
  7. /*                                                +#+#+#+#+#+   +#+           */
  8. /*   Created: 2019/07/14 20:44:39 by squiana           #+#    #+#             */
  9. /*   Updated: 2019/07/14 21:17:14 by ckumera          ###   ########.fr       */
  10. /*                                                                            */
  11. /* ************************************************************************** */
  12.  
  13. int     test_line(char **tab, char nb, int i)
  14. {
  15.     int j;
  16.  
  17.     j = 0;
  18.     while (j < 9)
  19.     {
  20.         if (tab[i][j] == nb)
  21.             return (0);
  22.         j++;
  23.     }
  24.     return (1);
  25. }
  26.  
  27. int     test_column(char **tab, char nb, int j)
  28. {
  29.     int i;
  30.  
  31.     i = 1;
  32.     while (i <= 9)
  33.     {
  34.         if (tab[i][j] == nb)
  35.             return (0);
  36.         i++;
  37.     }
  38.     return (1);
  39. }
  40.  
  41. int     test_block(char **tab, int i, int j, char nb)
  42. {
  43.     int x;
  44.     int y;
  45.  
  46.     x = -1;
  47.     if (i <= 3)
  48.         i = 1;
  49.     else if (i <= 6)
  50.         i = 4;
  51.     else if (i <= 9)
  52.         i = 7;
  53.     j = j - (j % 3);
  54.     while (++x < 3)
  55.     {
  56.         y = -1;
  57.         while (++y < 3)
  58.         {
  59.             if (tab[i][j] == nb)
  60.             return (0);
  61.             j++;
  62.         }
  63.         j = j - 3;
  64.         i++;
  65.     }
  66.     return (1);
  67. }
  68.  
  69. int     test_symbol(int n, char **tab)
  70. {
  71.     int i;
  72.     int j;
  73.  
  74.     i = 0;
  75.     if (n == 10)
  76.     {
  77.         while (++i <= 9)
  78.         {
  79.             j = 0;
  80.             while (tab[i][j])
  81.             {
  82.                 if ((tab[i][j] <= 48 || tab[i][j] > 57) && tab[i][j] != 46)
  83.                     return (0);
  84.                 j++;
  85.             }
  86.             if (j != 9)
  87.                 return (0);
  88.         }
  89.         return (1);
  90.     }
  91.     else
  92.         return (0);
  93. }
Add Comment
Please, Sign In to add comment