# recursive function problem

• 10-25-2002
jk81
recursive function problem
this function supposed to open all empty spaces..
but it does not work properly..

Code:

```void openemptyspace(int x, int y) {     /* Declarations */         int i;     int j; /* nested for loops and if statments*/         for(i = -1; i <= 1; i++)         {                 for(j = -1; j <= 1; j++)                 {                       if(showmines[x + i][y + j] == '-' )                       {                                         showmines[x + i][y + j] = mines[x + i][y + j];                                         if(showmines[x + i][y + j] == '0' )                       {                                                 openemptyspace(x + i, y + j);                       }  /* end if */                                     }    /* end outer if*/                 }  /*end inner for loop */         }  /* end outer for loop */ }```
• 10-25-2002
Hammer
>>but it does not work properly..
and? What does it do or not do that makes you think its wrong?
• 10-25-2002
dat
Re: recursive function problem
Quote:

Originally posted by jk81
this function supposed to open all empty spaces..
but it does not work properly..

Code:

```void openemptyspace(int x, int y) {     /* Declarations */         int i;     int j; /* nested for loops and if statments*/         for(i = -1; i <= 1; i++)         {                 for(j = -1; j <= 1; j++)                 {                       if(showmines[x + i][y + j] == '-' )                       {                                         showmines[x + i][y + j] = mines[x + i][y + j];                                         if(showmines[x + i][y + j] == '0' )                       {                                                 openemptyspace(x + i, y + j);                       }  /* end if */                                     }    /* end outer if*/                 }  /*end inner for loop */         }  /* end outer for loop */ }```

Usually in recursive functions the recursive part (the part where you call the function again) is not nested within a condition, and the "base case" is in an conditional statement. This style guarentees the the recursive call unless the base case is statisfied. With your style the:

Code:

```if(showmines[x + i][y + j] == '0' )                       {                                                 openemptyspace(x + i, y + j);                       }  /* end if */```
might not get called.

cheers