0

have any body another way to do this.

I should write a recursive function that finds and returns the length of a connected curve by counting the 'X' letters. The curve is uniquely determined by any starting point (m, n) that is on a curve itself.

#include <stdio.h>
#define M 5
#define N 8
char FELD[M][N] =   {
                    {'X','.','.','.','.','.','.','X'},
                    {'X','X','.','X','.','.','.','X'},
                    {'.','X','.','X','.','X','X','X'},
                    {'.','X','X','X','.','X','.','.'},
                    {'.','.','.','.','.','X','.','.'}
                    };
int arcno ( int m, int n){
    if((m < 0)||(m >= M)||(n < 0)||(n >= N)||(FELD[m][n] != 'X'))
    {
        return 0 ;
    }
    return 1 + arcno (m-1, n) + arcno (m+1, n) + arcno (m, n-1) + arcno (m, n+1);
}
int main(){
    int f = arcno(2, 3);
    printf("arcno = %d \n\n", f);
    for( int m = 0; m < M; m++) { for ( int n = 0; n < N; n++){
    printf("%c",FELD[m][n]);} printf ( "\n" );}
return 0 ;
}

I should get 9 but why I get Process returned -1073741571 (0xC00000FD) execution time : 3.675 s

Mo.x
  • 11
  • 2
  • 1
    return 1 + arcno (m-1, n) + arcno (m+1, n) + arcno (m, n-1) + arcno (m, n+1); this two functions call "arcno (m-1, n) + arcno (m+1, n)" are causing a stackoverflow you will aways get m=2; n=3 then m=1 n=3 then m=2 n=3 ....untill your stak overflow – phoenixstudio Aug 04 '19 at 23:23
  • I noticed that, but I do not know how to handle it – Mo.x Aug 04 '19 at 23:31
  • I had it ^_^ FELD[m][n] = 's';I just have to change the set characters – Mo.x Aug 04 '19 at 23:45
  • that was the mistake I had written 'X' instead of 'x' – Mo.x Aug 04 '19 at 23:54

1 Answers1

1

I got it ^_^ FELD[m][n] = 's';I just have to change the set characters FELD[m][n] = 'x';

int arcno ( int m, int n){
    if((m < 0)||(m >= M)||(n < 0)||(n >= N)||(FELD[m][n] != 'X'))
    {
        return 0 ;
    }
    FELD[m][n] = 'x'; //<==========
    return 1 + arcno (m-1, n) + arcno (m+1, n) + arcno (m, n-1) + arcno (m, n+1);
}
Mo.x
  • 11
  • 2