Sudoku Puzzle, not printing anything.

Discussion in 'OT Technology' started by SPACECATAZ, Feb 9, 2009.

  1. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0
    Hey guys, trying to get my sudoku puzzle to print the standard input that it receives from a .txt file, yet I'm unable to type anything in the console at all. It just says "Press any key to continue.." and doesn't give me the option to type any input. The bolded sections are where I'm having problems.

    Code:
    #include <iostream>
    #include <fstream>
    #include "intset.h"
    using namespace std;
    
    typedef SetOfSmallInts Puzzle[9][9];
    typedef SetOfSmallInts* PuzzleSection[9];
    /****************************************************************
     *                      copyPuzzle                              *
     ****************************************************************
     * Copy puzzle p into q.  For example, if p is a puzzle, then  *
     *    Puzzle q;                                                 *
     *    copyPuzzle(q, p);                                         *
     * stores a copy of puzzle p into q.                            *
     ****************************************************************/
    
    void copyPuzzle(Puzzle q, Puzzle p)
    {
      int i, j;
      for(i = 0; i < 9; i++) 
      {
        for(j = 0; j < 9; j++) 
        {
          q[i][j] = p[i][j];
        }
      }
    }
    
    /****************************************************************
     *                      getRow                                  *
     ****************************************************************
     * Store the i-th row of puzzle p into puzzle section R.    *
     * The rows are numbered from 0 to 8.                           *
     *                                                              *
     * After doing this, the k-th set in row i is *(R[k]).          *
     * Do not omit *(...). The cells in the row are numbered        *
     * 0,1,...,8.                                                   *
     ****************************************************************/
    
    void getRow(PuzzleSection R, Puzzle p, int i)
    {
      int j;
      for(j = 0; j < 9; j++) 
      {
        R[j] = &(p[i][j]);
      }
    }
    
    /****************************************************************
     *                      getColumn                               *
     ****************************************************************
     * Store the j-th column of puzzle p into puzzle section R.     *
     * The columns are numbered from 0 to 8.                *
     *                                                              *
     * After doing this, the k-th set in column j is                *
     * *(R[i]).  Do not omit *(...).  The cells in the              *
     * column are numbered 0,1,...,8.                               *
     ****************************************************************/
    
    void getColumn(PuzzleSection R, Puzzle p, int j)
    {
      int i;
      for(i = 0; i < 9; i++) 
      {
        R[i] = &(p[i][j]);
      }
    }
    
    /**************************************************************** 
     *                      getSquare                               *
     ****************************************************************
     * Store the k-th square of puzzle p into puzzle section R.     *
     * The squares are numbered as follows.                            *
     *           0 1 2                                              *
     *           3 4 5                                              *
     *           6 7 8                                              *
     * For example, square 4 is the middle square in the puzzle.    *
     *                                                              *
     * After doing getSquare, the i-th set in the square is *(R[i]).*
     * Do not omit *(...). The cells in the square are numbered     *
     * 0,1,...,8, in the same pattern shown above for the squares   *
     * themselves.  For example *(R[3]) is the first position in    *
     * the second row of the square.                                *
     ****************************************************************/
    
    void getSquare(PuzzleSection R, Puzzle p, int k)
    {
      int i;
      for(i = 0; i < 9; i++) 
      {
        R[i] = &(p[k - k%3 + i/3][3*(k%3) + i%3]);
      }
    }
    
    [B]/****************************************************************
     *                      readPuzzle                             *
     ****************************************************************
     * The readPuzzle function reads a puzzle from the standard     *
     * input then stores it into p.                                 *
     ****************************************************************/
    
    void readPuzzle(Puzzle p)
    {
    int i,j;
        for(i=0;i<9;i++)
        {
            for(j=0;j<9;j++)
            {
                char c;
                cin >> c; 
                if (c >= '1' && c <= '9') p[i][j] = singletonSet(c - '0');
                else if(c == '-') p[i][j] = rangeSet(1,9);       
            }
        }
    }[/B]
    
       
    //char buffer = '0';
    //ifstream puzzleFile;
    //puzzleFile.open("puzzle1.txt");
    //int countCol = 0;
    //int countRow = 0;
    // 
    //while(puzzleFile >> buffer)
    //  {
    //    if(buffer >= '1' && buffer <= '9') p[countRow][countCol] = singletonSet((buffer - '0')); //If input is between '1' and '9', it will take the input and minus '0' to get the singleton set.
    //
    //    if(buffer == '-') p[countRow][countCol] = singletonSet(0); //If it finds a '-', it will input a zero into its place instead.    
    //    countCol++;
    //    if(countCol == 9)
    //    {
    //    countCol = 0;
    //    countRow++;
    //    }
    //  }
    //}
    
    
    [B]/****************************************************************
     *                      printPuzzle                             *
     ****************************************************************
     * The printPuzzle function prints Puzzle p in standard output.    *
     * If the set is not a singleton set, then it will write a '-'  *
     * If it is empty, it will write a zero. If it is a             *
     * singleton set, then it will write a specific number into that*
     * set.                                                         *
     ****************************************************************/
    
    
    void printPuzzle(Puzzle p)
    {
       int single;
       for(int i=0;i<9;i++)
       {
          for(int j=0;j<9;j++)
          {
               single = onlyMember(p[i][j]); //If s is a singleton set, then onlyMember(s) returns the member of s. If s is not a singleton set, then onlyMember(s) returns 0. 
               if (j == 3 || j == 6) cout << " "; //Once it hits column 3 and 6, it will print a space.
               if (single == 0) cout << "-"; //If the singleton set is a 0, then it will print a "-".
               else cout << single;
           }
           if (i ==2 || i == 5) cout << "\n"; //Once it hits row 2 and 5, it will print a newline.
           cout <<"\n";
       }
    }[/B]
    
    /****************************************************************
     *                      showPuzzle                             *
     ****************************************************************
     * The showPuzzle function will print Puzzle p on the standard  *
     * output. If there is a particular set with a singleston or    *
     * multiple numbers, then it will print out all of those aswell.*
     * If a set is an emptyset then it will return a 0 for that set.*
     ****************************************************************/
    void showPuzzle(Puzzle p)
    {
    
    
    }
    
    
    int main()
    {
       Puzzle p;
       readPuzzle(p);
       printPuzzle(p);
       system("PAUSE");
    }
    
    Here's the include files and the input txt.
    Files I have to use to make it work,
    http://www.cs.ecu.edu/~karl/3300/spr09/sudoku/intset.h
    http://www.cs.ecu.edu/~karl/3300/spr09/sudoku/intset.cpp
    http://www.cs.ecu.edu/~karl/3300/spr09/sudoku/puzzle1.txt
     
    Last edited: Feb 10, 2009
  2. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0
    This is the sample input that I'm trying to get:
    1-- 489 --6
    73- --- -4-
    --- --1 295

    --7 12- 6--
    5-- 7-3 --8
    --6 -95 7--

    914 6-- ---
    -2- --- -37
    8-- 512 --4
     
  3. CodeX

    CodeX Guest

    where exactly is the class/structure definition for the "Puzzle" type?

    I might have just missed it, I only scanned the code briefly, there are more '*'s than there is code lol. Tell me your teacher makes you do that...
     
  4. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    i dont know why its not doing that cin line. It looks like it should definitely be getting there. what happens when you step through it in a debugger? also google "pass by reference" for your puzzle object
     
  5. CodeX

    CodeX Guest

    Yeah, thats what I was getting at with him passing the entire puzzle object by value... I think its screwing it up, but to know for sure I would have to see the definition of that class/struct.
     
  6. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0
    Yeah, he makes us put those in there. He calls them "contracts".

    For puzzle, it's:

    A puzzle is a 9x9 array of sets. If you include definition

    typedef SetOfSmallInts Puzzle[9][9];

    then you can use Puzzle as a type, indicating a 9x9 array of sets. If p has type puzzle, then p[j] is the set stored at row i, column j of p. The rows and columns are numbered from 0 to 8, not from 1 to 9. So the upper left corner of puzzle p is p[0][0] and the lower right corner is p[8][8].
     
  7. CodeX

    CodeX Guest

    oh I missed that lol... don't have time to look at this now but tomorrow after work ill copypasta it into visual studio and fix it to do what you want lol
     
  8. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0
    :bowdown::bowdown::bowdown::bowdown::bowdown::bowdown:
     
  9. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    Not sure what kind of problem you're having. When I compile and run the code, it allows me to enter data from the keyboard, reads the data, and then displays it. Can you be a little more specific about the problem you're having?
     
  10. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0
    It was the development environment. I'm using Dev C++, because when I compiled it under Linux. It was just fine. Such bullshittttt.
     
  11. CodeX

    CodeX Guest

    Visual studio ftw

    Glad you figured it out though
     
  12. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0

    :rofl:

    All the guys in my class and even professor think that VS should just go down the shitter completely. The microsoft hate they have is unbearable sometimes. I'm not really familiar with VS, but I'm like :dunno: whenever they're comparing development environments.
     
  13. CodeX

    CodeX Guest

    University environments are big on li/u/nix and open source because it is cheap/free and most people at the university level are poor.

    I remember distinctly the same mindless MS hatred at my school, very similar to how universities push java so hard when it nothing but a pipe dream. After you get out of school and work in the industry you get a more "full" view of the picture and realize that the stuff you were taught in school is ideological hippy bullshit and has little to do with the way the real world operates, lol.

    I have used many IDE's and nothing compares to VS once you know how to use it and all the features it offers. For example, Dev C++ is total shit, better than gcc though.
     
  14. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    I'm not a big fan of using something like VS for a small project of 2 or 3 source files. Often, with a project like that, Visual Studio just gets in the fucking way. I'd much rather use notepad++ and a compile script.
     
  15. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    javas pretty popular and great for writing UI apps dude.
     
  16. red

    red New Member

    Joined:
    Jun 30, 2005
    Messages:
    87,095
    Likes Received:
    0
    :ugh:
     
  17. trouphaz

    trouphaz New Member

    Joined:
    Sep 22, 2003
    Messages:
    2,666
    Likes Received:
    0
    i personally hate java due to it being a pig on resources, but it is very popular in corporate environments. to say it is a pipe dream is living with your head in the sand.
     
  18. CodeX

    CodeX Guest

    Java is C++ with arbitrary, and often crippling, restrictions... I don't see the appeal.

    And every "GUI app" I have seen written in java was a slow piece of shit. Maybe if your not developing for a windows environment but if you are you need to use .net in whatever your language of choice, I've used it in both VB and C++ and it's really a crap shoot as far as I am concerned as to which is better, its usually faster to type the equivalent VB code though.
     
  19. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    thanks for giving your insight with your vast professional programming experience
     

Share This Page