Traversing outer edges of array

Page 1 of 1

1 Replies - 586 Views - Last Post: 03 September 2013 - 07:17 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=328280&amp;s=80e53de18768b09d42ad8aff7f8069f4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 bdl1127

Reputation: 0
• 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

• D.I.C Lover

Reputation: 331
• 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.