SHARE
TWEET

sudoko

joelfmjr Apr 22nd, 2019 (edited) 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void verifica(int **m){
  5.   int aux1 = 0, aux2 = 0, flag = 0;
  6.   int h, i, j;
  7.   for(h = 0; h < 9; h++){
  8.     for(i = aux1; i < aux1+3; i++){
  9.       for(j = aux2; j < aux2+3; j++){
  10.         if(!(m[i][j] <= 9 && m[i][j] >= 1)){
  11.           flag = 1;
  12.           break;
  13.         }
  14.       }
  15.       if(flag)break;
  16.       aux2 += 3;
  17.     }
  18.     if(flag)break;
  19.     aux1++;
  20.     aux2 = 0;
  21.   }
  22.   if(flag){
  23.     printf("N\n");
  24.   }else{
  25.     printf("S\n");
  26.   }
  27. }
  28. int main(){
  29.  
  30.     FILE *myFile;
  31.     myFile = fopen("numbers.txt", "r");
  32.  
  33.     //read file into array
  34.     int i, j;
  35.     int **sudoku = calloc(9, sizeof(int*));
  36.     for(i = 0; i < 9; i++){
  37.         sudoku[i] = calloc(9, sizeof(int));
  38.     }
  39.  
  40.     if (myFile == NULL){
  41.         printf("Error Reading File\n");
  42.         exit (0);
  43.     }
  44.  
  45.     for (i = 0; i < 9; i++){
  46.         for(j = 0; j < 9; j++){
  47.             fscanf(myFile, "%d ", &sudoku[i][j]);
  48.         }
  49.     }
  50.  
  51.     for (i = 0; i < 9; i++){
  52.         for(j = 0; j < 9; j++){
  53.             printf("%d ", sudoku[i][j]);
  54.         }
  55.         printf("\n");
  56.     }
  57.     verifica(sudoku);
  58.  
  59.     fclose(myFile);
  60.     for(i = 0; i < 9; i++){
  61.       free(sudoku[i]);
  62.     }
  63.     free(sudoku);
  64.  
  65.     return 0;
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top