1 Replies - 306 Views - Last Post: 03 September 2013 - 07:17 PM Rate Topic: -----

#1 bdl1127  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 03-September 13

Traversing outer edges of array

Posted 03 September 2013 - 06:39 PM

All,

I am brand new to C and am still figuring things out. I am working on a maze solver right not, but first have to write a function that finds the starting point of the maze! In order to do this, I need to traverse the outer walls of my array(maze) in counter-clockwise direction starting from [0,0]. I will post my code below. I may be on the right track, or completely off. Please criticize, tell me if im on the right track, and help me out, as I am new to this

Maze walls denoted by 1's
Maze openings denoted by 0's

findStart(char array[rows][cols]) {

//traverses leftern-most edge of maze from top down
int i;
for(i = 0; i < rows; i++) {
  if(array[i][0] == '0') {
     //found starting point
   }
}
// traverses bottom edge of maze from left to right
int j;
for(j = 0; j < cols; j++) {
  if(array[rows][j] == '0') {
     //found starting point
   }
}
// traverses right-most edge of maze from bottom to top
int k;
for(k = rows; k > 0; k--) {
  if(array[k][cols] == '0') {
     //found starting point
   }
}
traverses upper edge of maze from right to left
int m;
for(m = cols; m > 0; m--) {
  if(array[0][m] == '0') {
     //found starting point
   }
}

}




Is This A Good Question/Topic? 0
  • +

Replies To: Traversing outer edges of array

#2 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Traversing outer edges of array

Posted 03 September 2013 - 07:17 PM

You're on the right track, but array[rows][cols], in C, means the highest valid row is row-1, and the highest valid col is cols-1, so you are currently going a bit too far with both rows and cols.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1