Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. #define SIZE 9
  6.  
  7. typedef struct {
  8.     int board[SIZE][SIZE];
  9.  
  10.     int *rows[SIZE];
  11.     int *columns[SIZE];
  12.     int *boxes[SIZE];
  13. } sudoku ;
  14.  
  15. void readBoard(sudoku s, char *filename);
  16. void parseBoard(int board[][SIZE]);
  17.  
  18. int main(int argc, char *argv[])
  19. {
  20.     if(--argc > 0) {
  21.     static sudoku mysudoku;
  22.     readBoard(mysudoku, argv[1]);
  23.     parseBoard(mysudoku.board);
  24.     }
  25.     else
  26.     printf("Missing command line argument\n");
  27. }
  28.  
  29. void readBoard(sudoku s, char *filename) {
  30.     FILE *fp = fopen(filename, "r");
  31.    
  32.     for (int i = 0; i < SIZE; ++i) {
  33.     for (int j = 0; j < SIZE; ++j) {
  34.         char c = fgetc(fp);
  35.         if (isdigit(c)) { //if number
  36.         s.board[i][j] = atoi(&c);
  37.         } else if(c == '.') { //if blank
  38.         s.board[i][j] = 0;
  39.         }
  40.     }
  41.     }
  42.  
  43.     fclose(fp);
  44. }
  45.  
  46. void parseBoard(int board[][SIZE]) {
  47.     printf("Hello");
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement