• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 883
  • Last Modified:

URGENT - linking problem

I am trying to acces the exit point of the maze.
But I could not compile it because of the header file link error.
What changes should I do to be able not to get any error?
Which cpp and header files should be included in this project and how?
My code is as follows;


#include <stack.h>
#include <conio.h>
#include <iostream.h>
#include <fstream.h>

// Maze -- // -1 : border wall //  0 : empty // +1 : wall
void Init_Maze(int maze[][4], const int width, const int height)
 {
  int numcells = width * height;

  for(int cell=0; cell<numcells; cell++)
    for(int i=0; i<4; i++)
     maze[cell][i] = 1;

  // place border - top
  for(int column=0; column<width; column++)
   {
    maze[column][0] = -1;
    maze[numcells-column-1][2] = -1;
   }
  for(int row=0; row<height; row++)
   {
    maze[width*row][3] = -1;
    maze[(width*row)+(width-1)][1] = -1;
   }
}

// Print map of maze
void Cool_Draw_Maze(int maze[][4], const int width, const int height, std::ofstream &str)
 {
  for(int row=0; row<height; row++)
   {
    // Print top
    int r = (row*width);
    for(int col=0; col<width; col++)
     {
      str << "+";
      switch( maze[r+col][0] )
       {
        case -1 : str << "="; break;
        case 0  : str << " "; break;
        case  1 : str << "-"; break;
       }
      if( (col==(width-1)) ) str << "+";
     }
    str << std::endl;
    // Next line, Print middle
    for(int col=0; col<width; col++)
     {
      switch( maze[r+col][3] )
       {
        case -1 : str << "!"; break;
        case 0  : str << " "; break;
        case  1 : str << "|"; break;
       }
      str << " ";
      if( col==(width-1) )
       {
        switch( maze[r+col][1] )
         {
          case -1 : str << "!"; break;
          case 0  : str << " "; break;
         }
        }
      }
     str << std::endl;
   }
    // Print bottom, Last row
    for(int cell=(width*(height-1)); cell<(width*height); cell++)
     {
      str << "+";
      switch( maze[cell][2] )
       {
        case -1 : str << "="; break;
        case 0  : str << " "; break;
       }
      if( cell==(width*height)-1 ) str << "+";
     }
    str << std::endl;
 }

int cell_at(int cell, int direction, int width)
 {
  switch(direction)
   {
    case 0: return cell-width;
    case 1: return cell+1;
    case 2: return cell+width;
    case 3: return cell-1;
   }
  return -1;
 }

void Print_Maze_Solution(int maze[][4], const int width, const int height, std::ofstream &str)
 {
  int numcells = width*height;
  str << width << " " << height << std::endl;
  // Start point : the top left !!!!!!!!!
  // End Point   : the bottom right. !!!!
  str << "1 " << (width*height) << std::endl;
  for(int cell=0; cell<numcells; cell++)
   for(int i=0; i<4; i++)
    if(!maze[cell][i])
     str << cell+1 << " " << cell_at(cell,i,width)+1 << std::endl;
 }


// Count the (breakable) walls around this cell
int Walls(int maze[][4], const int cell)
 {
  int w=0;
  for(int i=0; i<4; i++)
   if(maze[cell][i]==1) w++;
  return w;
 }

// Does this cell have all 4 walls?
int Sealed(int maze[][4], const int cell)
 {
  int w=0;
  for(int i=0; i<4; i++)
   if(maze[cell][i]) w++;
  return (w==4);
 }

// Return walled neighbours count
int Neighbours(int maze[][4], int neighbours[4], int cell, int width, int height)
 {
  int count=0;
  if( Sealed(maze, cell-width) && (cell>width) )
   neighbours[count++]=cell-width;

  if( Sealed(maze, cell+1) && ((cell%width)!=(width-1)) )
   neighbours[count++]=cell+1;

  if( Sealed(maze, cell+width) && (cell<(width*(height-1))) )
   neighbours[count++]=cell+width;
  if( Sealed(maze, cell-1) && ((cell%width)!=0) )
   neighbours[count++]=cell-1;

  return count;
 }


int Break_Between(int maze[][4], const int cell1, const int cell2, int width)
 {
  if( cell2 == cell1-width )
   { // North from cell1
    maze[cell1][0] = 0;
    maze[cell2][2] = 0;
   }
  if( cell2 == cell1+width )
   { // South from cell1
    maze[cell1][2] = 0;
    maze[cell2][0] = 0;
   }
  if(cell2 == cell1+1)
   { // East from cell1
    maze[cell1][1] = 0;
    maze[cell2][3] = 0;
   }
  if(cell2 == cell1-1)
   { // West from cell1
    maze[cell1][3] = 0;
    maze[cell2][1] = 0;
   }
  return cell2;
}

void Create_Maze(int maze[][4], const int width, const int height)
 {
  int remaining = (width*height)-1;
  int currentcell = rand()%remaining;
  int nbrs[4];
  std::stack<int> s;
  while(remaining > 0)
   {
    int count = Neighbours(maze,nbrs,currentcell,width,height);
    if( count>0 )
     {
      s.push(currentcell);
      currentcell = Break_Between(maze,currentcell,nbrs[ rand() % count ],width );
      remaining--;
     }
    else
     {
      currentcell = s.top();
      s.pop();
     }
   }
}

int Border(int maze[][4], int cell)
 {
  int w = 0;
  for(int i=0; i<4; i++)
   if( maze[cell][i]==-1 )
    w++;
  return w;
}

int main(int argc, const char **argv)
 {
  std::stack<int> s;
  std::string filename;
  int maze[20*20][4];
  // Seed the random number generator
  srand(time(NULL));

  // Select maze size
  int width, height;
  if(argc >=3)
   {
    width  = atoi(argv[1]);
    height = atoi(argv[2]);
   }
  else
   {
    std::cout << "Enter Maze Width & Height. !!!!\n";
    std::cout << "Enter Width : ";
    std::cin  >> width;
    std::cout << "Enter Height : ";
    std::cin  >> height;
   }

  // Create a random maze
  Init_Maze(maze, width, height);
  Create_Maze(maze, width, height);

  // Select base filename
  if( argc >= 4 ) filename = std::string(argv[3]);
  else
   {
    std::cout << "Enter base filename: ";
    std::cin  >> filename;
   }
  // Display output
  std::ofstream drawMaze( (filename+".maz").c_str() );
  Cool_Draw_Maze(maze, width, height, drawMaze);

  std::ofstream pathFollowerFile( (filename+".sol").c_str() );
  Print_Maze_Solution(maze, width, height, pathFollowerFile);

  cout<<"Maze and solution files are created...!!!\n";
  getch();
  return 0;
}

-----------------------------------------------------------------------------------------------------------------
The error is;

Compiling...
untMaze.cpp
c:\....\untmaze\untmaze.cpp(1) : fatal error C1083: Cannot open include file: 'stack.h': No such file or directory
Error executing cl.exe.

untMaze.obj - 1 error(s), 0 warning(s)
0
aylinyzc
Asked:
aylinyzc
  • 5
  • 2
1 Solution
 
trigger-happyCommented:
you have to make sure that stack.h exists. If it is in a different location, you'll hvae to  configure the path where the include files are from within the VC++ settings.

--trigger-happy
0
 
aylinyzcAuthor Commented:
I could not fix it.
I am getting the same error.
Should I have to add anything to this projects other than the maze.cpp (in my first question) and the stack.h (below);


/*************stack.h*********************/

#ifndef __STACK_H
#define __STACK_H
#pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
// -*- C++ -*-
#ifndef __STD_STACK__
#define __STD_STACK__

/***************************************************************************
*
* stack - Declaration for the Standard Library stack class
*
***************************************************************************
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
***************************************************************************
*
* Copyright (c) 1994-1999 Rogue Wave Software, Inc. All Rights Reserved.
*
* This computer software is owned by Rogue Wave Software, Inc. and is
* protected by U.S. copyright laws and other laws and by international
* treaties. This computer software is furnished by Rogue Wave Software,
* Inc. pursuant to a written license agreement and may be used, copied,
* transmitted, and stored only in accordance with the terms of such
* license and with the inclusion of the above copyright notice. This
* computer software or any other copies thereof may not be provided or
* otherwise made available to any other person.
*
* U.S. Government Restricted Rights. This computer software is provided
* with Restricted Rights. Use, duplication, or disclosure by the
* Government is subject to restrictions as set forth in subparagraph (c)
* (1) (ii) of The Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
* Commercial Computer Software – Restricted Rights at 48 CFR 52.227-19,
* as applicable. Manufacturer is Rogue Wave Software, Inc., 5500
* Flatiron Parkway, Boulder, Colorado 80301 USA.
*
**************************************************************************/

#include <stdcomp.h>

#include <oldstl/algorithm>
#include <oldstl/deque>

#ifndef _RWSTD_NO_NAMESPACE
namespace std {
#endif

template <class T, class Container _RWSTD_COMPLEX_DEFAULT(deque<T>) > 
class stack;

#ifdef _RWSTD_NO_UNDEFINED_FRIEND
template <class T, class Container>
inline bool operator==(const stack<T,Container>& x,
const stack<T,Container>& y);
template <class T, class Container>
inline bool operator<(const stack<T,Container>& x,
const stack<T,Container>& y);
#endif

template <class T, class Container>
class stack
{
#ifdef __TURBOC__
friend bool (std::operator==) (const stack<T,Container>& x,
const stack<T,Container>& y);
friend bool (std::operator<) (const stack<T,Container>& x,
const stack<T,Container>& y);
#else
friend bool operator== (const stack<T,Container>& x,
const stack<T,Container>& y);
friend bool operator< (const stack<T,Container>& x,
const stack<T,Container>& y);
#endif
public:

typedef _TYPENAME Container::value_type value_type;
typedef _TYPENAME Container::size_type size_type;
typedef _TYPENAME Container::reference reference;
typedef _TYPENAME Container::const_reference const_reference;
typedef Container container_type;

protected:

Container c;

public:
_EXPLICIT stack(const Container& co _RWSTD_DEFAULT_ARG(Container()))
: c(co)
{ ; }

#ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
stack(void) : c(Container())
{ ; }
#endif

bool empty () const { return c.empty(); }
size_type size () const { return c.size(); }
reference top () { return c.back(); }
const_reference top () const { return c.back(); }
void push (const value_type& x) { c.push_back(x); }
void pop () { c.pop_back(); }
};

template <class T, class Container>
inline bool operator== (const stack<T,Container>& x,
const stack<T,Container>& y)
{
return x.c == y.c;
}

template <class T, class Container>
inline bool operator< (const stack<T,Container>& x,
const stack<T,Container>& y)
{
return x.c < y.c;
}

template <class T, class Container>
inline bool operator!= (const stack<T,Container>& x,
const stack<T,Container>& y)
{
return !(x == y);
}

template <class T, class Container>
inline bool operator> (const stack<T,Container>& x,
const stack<T,Container>& y)
{
return y < x;
}

template <class T, class Container>
inline bool operator>= (const stack<T,Container>& x,
const stack<T,Container>& y)
{
return !(x < y);
}

template <class T, class Container>
inline bool operator<= (const stack<T,Container>& x,
const stack<T,Container>& y)
{
return !(y < x);
}

#ifndef _RWSTD_NO_NAMESPACE
}
#endif

#endif /*__STD_STACK__*/


#pragma option pop
#endif /* __STACK_H */
0
 
trigger-happyCommented:
...i just realized something...instead of using <stack.h>, try using <stack>

--trigger-happy
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aylinyzcAuthor Commented:
I had tried it but then the result were 47 errors.
I am asking the same question but I am still not sure whether I should include any other files to the project other than maze. cpp(in my first question) and the stack.h (below).
for examle should I add stack.cpp or else?
0
 
guitaristxCommented:
replace

#include <stack.h>
#include <conio.h>
#include <iostream.h>
#include <fstream.h>

with

#include <stack>
#include <conio.h>
#include <iostream>
#include <fstream>
using namespace std;

The reason for this is that stack.h, iostream.h, and fstream.h are all deprecated.  The de facto standard for C++ standard library include files is what you see above.  The conio.h file should still be fine (i think).
0
 
aylinyzcAuthor Commented:
ok this solves the stack.h problem, thank you!
but now there are 9 errors and some of them are about redefinition
I did not add any header or source file other than the untMaze.cpp
Any idea?


Compiling...
untMaze.cpp
d:\untmaze\untmaze.cpp(50) : error C2374: 'col' : redefinition; multiple initialization
        d:\untmaze\untmaze.cpp(37) : see declaration of 'col'
d:\untmaze\untmaze.cpp(210) : error C2065: 'time' : undeclared identifier
d:\untmaze\untmaze.cpp(237) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
d:\untmaze\untmaze.cpp(240) : error C2784: 'class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> __cdecl std::operator +(_D,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce template argument for '' from 'class std::basic_strin
g<char,struct std::char_traits<char>,class std::allocator<char> >'
d:\untmaze\untmaze.cpp(240) : error C2676: binary '+' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
d:\untmaze\untmaze.cpp(240) : error C2228: left of '.c_str' must have class/struct/union type
d:\untmaze\untmaze.cpp(243) : error C2784: 'class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> __cdecl std::operator +(_D,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce template argument for '' from 'class std::basic_strin
g<char,struct std::char_traits<char>,class std::allocator<char> >'
d:\untmaze\untmaze.cpp(243) : error C2676: binary '+' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
d:\untmaze\untmaze.cpp(243) : error C2228: left of '.c_str' must have class/struct/union type
Error executing cl.exe.

untMaze.obj - 9 error(s), 0 warning(s)


0
 
aylinyzcAuthor Commented:
I add

#include <string>

and then the number of errors decreases to 2.
but I've still errors
Please help for those errors;

Compiling...
untMaze.cpp
d:\untmaze\untmaze.cpp(51) : error C2374: 'col' : redefinition; multiple initialization
        d:\untmaze\untmaze.cpp(38) : see declaration of 'col'

d:\untmaze\untmaze.cpp(211) : error C2065: 'time' : undeclared identifier
Error executing cl.exe.

untMaze.obj - 2 error(s), 0 warning(s)
0
 
aylinyzcAuthor Commented:
Sorry, I could not see the very simple solution.
There is no error any more!

there is one more thing that I want to ask;
In the code in my first message, I want to change the style of the program;
I do not want to create the maze randomly, but from the input file like this;

10 10
1 5
1 1 1 1 0 1 1 1 1 1
1 0 0 1 0 1 0 0 0 1
1 0 0 0 0 0 0 1 0 1
1 0 1 1 1 1 0 1 0 1
1 0 1 0 0 1 0 1 0 1
1 0 1 1 1 1 0 0 0 1
1 1 1 0 1 0 0 1 0 1
0 0 1 0 1 0 1 1 0 0
1 0 1 0 0 0 0 0 0 1
1 0 1 1 1 1 1 1 1 1
describes a maze of 10 rows by 10 columns whose start point is at coordinates (x=1,
y=5) .
The user should type the input in this order(above) and then print the output as below.
The code will first print the input data to the standard output as shown above
and will then produce the following output showing path from the entrance point
to an exit point in terms of pairs of numbers, giving coordinates of the points on
the path.
For the example above, the code should produce the following output after the input is printed
The solution to the puzzle is:
1 5
2 5
3 5
3 6
3 7
4 7
5 7
6 7
6 8
6 9
7 9
8 9
8 10

How can I do this in a simple way?
Can you give a sample code for this?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now