title: How to get input from another file for my Sudoku game C using a .txt file
body: <p>Alright so my problem is that I have no idea where to go in my situation with my Sudoku Program. As of right now I have multiple programs that work together to create my Sudoku program which is SUPPOSED to take input of 9 lines with 9 characters each whether it be just spaces or numbers.
  example:</p>
  
  <pre><code>53  7    
  6  195   
   98    6
  8   6   3
  4  8 3  1
  7   2   6
   6    28
     419  5
      8   79
  </code></pre>
  
  <p>What the program would yield would be:</p>
  
  <pre><code>534678912
  672195348
  198342567
  859761423
  426853791
  713924856
  961537284
  287419635
  345286179
  </code></pre>
  
  <p>My current programs consist of the files stack.h, stack.cc, sudokuboard.h sudokuboard.cc, sudoku.cc, and Makefile, as well as test.txt(consists the example of input i had above)</p>
  
  <p>the programs stack.h:</p>
  
  <pre><code>struct Node {
    StackElementType data;
    Node *next;
  };
  class Stack {
   public:
  
   Stack(); //constructor
   ~Stack(); //deconstructor
   Stack(const Stack &amp; orig); // copy constructor
   void output(ostream &amp; ostr) const; //output method
   bool empty() const; // if empty returns true
   void push(const StackElementType &amp; item); // puts new item on top of stack
   void pop(); // removes top element of nonempty stack
   StackElementType top() const; // returns copy of top element of a stack
  
   private:
   Node*first;
   size_t _size;
  }
  </code></pre>
  
  <p>Note that there may be misspellings in this due to having to being unable to copy my code directly so most of this is freshly typed out. </p>
  
  <p>My stack.cc is </p>
  
  <pre><code>#include "stack.h"
  #include &lt;cstdlib&gt;
  #include &lt;cassert&gt;
  
  void destroy(Node *p)
  {
    // delete all nodes dominated by p.
    while (p != NULL) {
      Node *old = p;
      p = p-&gt;next;
      delete old;
    }
  }
  
  Node *copy(Node *p)
  {
    // Make a deep copy of linked list dominated by p.
    Node *result = NULL;
    if (p != NULL) {
      result = new Node;
      Node *last = result;
      while (p != NULL) {
        // invariant: last points to a node ready to receive p's data.
        last-&gt;data = p-&gt;data;
        last-&gt;next = NULL;
        p = p-&gt;next;
        if (p != NULL) {
      // there's going to more to this copy.  Get it ready.
      last-&gt;next = new Node;
      last = last-&gt;next;
        }
      }
    }
    return result;
  }
  
  Stack::Stack()
  {
    first = NULL;
  }
  
  Stack::~Stack()
  {
    destroy(first);
  }
  
  Stack::Stack(const Stack &amp; orig)
  {
    first = copy(orig.first);
  }
  
  Stack &amp; Stack::operator=(const Stack &amp; rhs)
  {
    if (this != &amp;rhs) 
      first = copy(rhs.first);
    return *this;
  }
  
  void Stack::output(ostream &amp; ostr) const
  {
    ostr &lt;&lt; "&lt;";
    for(Node *p = first;p;p=p-&gt;next) {
      ostr &lt;&lt; p-&gt;data;
      if (p-&gt;next)
        ostr &lt;&lt; ", ";
    }
    ostr &lt;&lt; "&gt;";
  }
  
  void Stack::push(const ElementType &amp; item)
  {
    Node *born = new Node;
    born-&gt;data = item;
    born-&gt;next = first;
    first = born;
  }
  
  void Stack::pop()
  {
    assert(!empty());
    Node *rest = first-&gt;next;
    delete first;
    first = rest;
  }
  
  ElementType Stack::top() const
  {
    assert(!empty());
    return first-&gt;data;
  }
  
  bool Stack::empty() const
  {
    return first==NULL;
  }
  </code></pre>
  
  <p>So this is simply what I am using for my stack</p>
  
  <p>My sudokuboard.h:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #define SDIM 9
  
  class SudokuBoard {
   public:
    //------------------------------------------------------------------------
    SudokuBoard();
    // Construct a blank sudoku board
    //------------------------------------------------------------------------
  
    //------------------------------------------------------------------------
    void print(std::ostream &amp; ostr) const;
    // display it.  duh.
    //------------------------------------------------------------------------
  
    //------------------------------------------------------------------------
    void place(size_t r, size_t c, char digit);
    // PRE: safe(r,c,digit)
    //------------------------------------------------------------------------
  
    //------------------------------------------------------------------------
    void remove(size_t r, size_t c, char digit); 
    // PRE: get(r,c) == digit
    //------------------------------------------------------------------------
  
    //------------------------------------------------------------------------
    char get(size_t r, size_t c) const;
    // Return the digit at (r,c) on the board.  or ' ' if blank.
    //------------------------------------------------------------------------
  
    //------------------------------------------------------------------------
    bool safe(size_t r, size_t c, char digit) const;
    // 
    //------------------------------------------------------------------------
  
    //------------------------------------------------------------------------
    bool done() const; 
    // Return true iff every cell has a number
    //------------------------------------------------------------------------
   private:
    std::string rows[SDIM];
  };
  </code></pre>
  
  <p>While my sudokuboard.cc</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cassert&gt;
  #include "sudokuboard.h"
  
  #define ASSERTBOUNDS assert(0 &lt;= r and r &lt; SDIM and 0 &lt;= c and c &lt; SDIM)
  
  SudokuBoard::SudokuBoard()
  {
    for (size_t i = 0;i&lt;SDIM;i++) {
      rows[i] = "";
      for (size_t j=0;j&lt;SDIM;j++)
        rows[i] += ' ';
    }
  }
  
  void SudokuBoard::place(size_t r, size_t c, char digit)
  {
    ASSERTBOUNDS;
    assert(safe(r,c,digit));
  }
  
  void SudokuBoard::remove(size_t r, size_t c, char digit)
  {
    ASSERTBOUNDS;
    assert(get(r,c)==digit);
    rows[r][c] = ' ';
  }
  
  char SudokuBoard::get(size_t r, size_t c) const
  {
    ASSERTBOUNDS;
    return rows[r][c];
  }
  
  
  void SudokuBoard::print(std::ostream &amp; ostr) const
  {
    for (size_t i=0;i&lt;SDIM;i++)
      ostr &lt;&lt; rows[i] &lt;&lt; std::endl;
  }
  bool SudokuBoard::safe(size_t r, size_t c, char digit) const
  {
   for(size_t r=0; r&lt;SDIM; r++)
      for(size_t c=0; c&lt;SDIM; c++)
         if (get(r,c) == digit)
             return false;
  
   for(size_t c=0; c&lt;SDIM; c++)
      for(size_t r=0; r&lt;SDIM; r++)
         if (get(r,c) == digit)
             return false;
    return true;
  }
  bool SudokuBoard::done() const
  {
    for (size_t r=0;r&lt;SDIM;r++)
      for (size_t c=0;c&lt;SDIM;c++)
        if (rows[r][c]==' ')
      return false;
    return true;
  }
  </code></pre>
  
  <p>My sudoku.cc right now is pretty much blank because I have only a general idea on how to pursue my goal. The way I am going to fill in the empty spaces is that I am going to take to take a single area and put in the smallest possible number in its current row/column and if there is a higher number in its row/column is goes up +1. I then go down the column and so on.</p>
  
  <p>My question is how do i integrate the following programs of sudokuboard.cc and stack.cc in my sudoku.cc. I know I have to get the input of test.txt some how and convert each of the lines to the empty board, but I don't know how to phrase the cin input for that at all!</p>
  
  <p>In other words I am looking for any help to get my sudok.cc started and how should I approach it? </p>
  
  <p>sudoku.cc</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cassert&gt;
  #include "sudokuboard.h"
  #include "stack.h"
  
  int main()
  {
  
  
  }
  </code></pre>
  
  <p>I just want to say thank you who gave me these answers, now my lab is well on its way thanks to you guys! I cannot give any of you points b/c my rep is too low but otherwise i would!</p>