-2
int checkWinDiagonals(char board[N][M])
{

for(int i = 0; i < (N-3); i++)
{
    for(int j = 0; j < (M-3); j++)
    {
 if(board[i][j] != ' ' && board[i][j] == board[i+1][j+1])
        {
if (board[i][j] == board[i+2][j+2] && board[i][j] == board[i+3][j+3])
    {
      return 1;
    }

        }
    }
}

for(int i = 0; i < (N-3); i++)

{
 for(int j = 3; j < M; j++)
{
if(board[i][j] != ' ' && board[i][j] == board[i+1][j-1])
    {

if( board[i][j] == board[i+2][j-2] && board[i][j] == board[i+3][j-3])
        {
            return 1;
        }
    }
}
return 0;
 }
}

I get this error "control reaches end of non-void function".Forget int main() because this is just a piece of the code in which it doesnt work.Do I have to put return (something); in some place?

CSDude101
  • 171
  • 9
  • 1
    Checkout the meaning of that error [http://stackoverflow.com/questions/6171500/what-does-control-reaches-end-of-non-void-function-mean](http://stackoverflow.com/questions/6171500/what-does-control-reaches-end-of-non-void-function-mean) – Luis May 25 '15 at 23:53

1 Answers1

0

You should really format your code with consistent indentation to make errors like this a lot easier to spot. But I suspect the problem is right here:

//...
        }
        return 0;
    }
    // right here
}

What happens at runtime if those loops have nothing over which to iterate and are skipped entirely? Or various if blocks don't evaluate to true and are skipped? The end of the function is reached and nothing is returned, but the function is declared to return an int so something must be returned.

You need to structure your code to always return a value in any logical case. Which in this case may involve returning a default value at the end of none of the preceding logic returned anything.

David
  • 208,112
  • 36
  • 198
  • 279