🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.nowe-programy
Article #228394

C++ program-- can anyone find the problem in this program ???

#228394
From: ¸¸.ˇ´Ż` F. KAH Ż`ˇ.¸¸.
Date: Wed, 11 Feb 1998 08:27
135 lines
4391 bytes
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

#define PRINTWALL cout<<"1"
#define FALSE 0
#define TRUE (-1)
#define MAX_PATH 120

enum dir_type {N,NE,E,SE,S,SW,W,NW,NONE};

 struct path_stk_type
 {
 unsigned int row,col;
 dir_type dir;
 };

struct move_type
 {
 short int a,b;
 };

int find_path(char *);
void push(path_stk_type,int &,int,int,int);
void pop(path_stk_type,int &,int,int,int);

void main(void)
{
 char maze[22][22];   //read info. 0 and 1
 int  noc,nor,i,j;

 ifstream fobj("indata2.txt",ios::in);
  if(!fobj)
   {
     cout<<"Cannot open the file\n";
     exit(1);
   }

    while(!fobj.eof()) //fobj is your file object
    {
     fobj>>nor;
     fobj>>noc;
     for(i=0;i<noc+2;i++) PRINTWALL;
     cout<<"\n";
     for(i=0;i<nor;i++)
     {
     PRINTWALL;
     for(j=0;j<noc;j++)
      {
      fobj>>maze[i][j];
      cout<<maze[i][j];
      }
     cout<<"1\n";
    }
    for(i=0;i<noc+2;i++) PRINTWALL;
    break;
    }
 } // main

int find_path(char *maze)
  {

      int maze_mark[20][20];
      path_stk_type path_stk[MAX_PATH];
      int stk_top;


     move_type move[NONE];  /* NONE is an enum element */
              /* declared above.         */

     move[N].a=(-1);       move[N].b=0;
     move[NE].a=(-1);      move[NE].b=1;
     move[E].a=0;          move[E].b=1;
     move[SE].a=1;         move[SE].b=1;
     move[S].a=1;          move[S].b=0;
     move[SW].a=1;         move[SW].b=(-1);
     move[W].a=0;          move[W].b=(-1);
     move[NW].a=(-1);      move[NW].b=(-1);


 char path_found=FALSE;
 int cur_row=1, cur_col=1,next_row,next_col;
 dir_type dir=N;
 stk_top=(-1);
 push(*path_stk,stk_top,cur_row,cur_col,dir);
 while(stk_top > (-1) && !path_found)
   {
  pop(*path_stk,stk_top,cur_row,cur_col,dir);
  while(dir <= NW && !path_found)
    {
   next_row=cur_row + move[dir].a;
   next_col=cur_col + move[dir].b;
   if(maze[cur_row][cur_col] == "0")
     {
    path_found=TRUE;
    push(*path_stk,stk_top,cur_row,cur_col,dir);
     } // if
   else if(maze[next_row][next_col]=="0")
     if(maze_mark[cur_row][cur_col]=="0")
     {
      maze_mark[cur_row][cur_col]=="1";
      push(*path_stk,stk_top,row,col,dir+NE)
      cur_row=next_row
      cur_col=next_col
      dir=N;
     } // if
     else
     dir=(dir_type)(dir + NE);
   else
     dir=(dir_type)(dir + NE);
    } // inner while
   } // outer while
 if(!path_found)
  Return 0;
 else
  Return 1;
  }  // find_path


void push(stack,&top,row,col,dir)
 {
 ++top;
 stack[top].row=row;
 stack[top].col=col;
 stack[top].dir=dir;
 } /* push */


void pop(stack,&top,&row,&col,&dir)
 {
 row=stack[top].row;
 col=stack[top].col;
 dir=stack[top].dir;
 --top;
 } /* pop */
Technical Details
Message-ID: <34E160EB.2E4AA2F9@SPOTCOM.COM>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.nask.pl!fci-se!fci!news-out.internetmci.com!newsfeed.internetmci.com!206.250.118.17!nntp.earthlink.net!usenet

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.nask.pl!fci-se!fci!news-out.internetmci.com!newsfeed.internetmci.com!206.250.118.17!nntp.earthlink.net!usenet
From: ¸¸.ˇ´Ż` F. KAH Ż`ˇ.¸¸.
 <FARID@SPOTCOM.COM>
Newsgroups: microsoft.public.win32.programmer.gdi,microsoft.public.win32.programmer.installwizard.beta,microsoft.public.win32.programmer.international,microsoft.public.win32.programmer.kernel,microsoft.public.win32.programmer.mapi,microsoft.public.win32.programmer.mmedia,microsoft.public.win32.programmer.networks,microsoft.public.win32.programmer.ole,microsoft.public.win32.programmer.pen,microsoft.public.win32.programmer.tapi,microsoft.public.win32.programmer.tools,microsoft.public.win32.programmer.ui,microsoft.public.win32.programmer.wince,microsoft.public.word.programming,nl.comp.programmeren,no.slekt.programmer,pl.comp.nowe-programy,pl.comp.programming,rec.games.programmer,rec.games.xtank.programmer,semcog.prog-admin.fed-programs,srg.programme,symantec.support.devtools.mac.cafe.programmer,symantec.support.devtools.mac.sc++.programmer,symantec.support.devtools.mac.visual-cafe.programmer
Subject: C++ program-- can anyone find the problem in this program ???
Date: Wed, 11 Feb 1998 00:27:23 -0800
Organization: COMPUTER SERVICES
Lines: 135
Message-ID: <34E160EB.2E4AA2F9@SPOTCOM.COM>
Reply-To: FARID@SPOTCOM.COM
NNTP-Posting-Host: 153.37.178.41
Mime-Version: 1.0
X-Mailer: Mozilla 4.04 [en] (Win95; I)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit