But if you have one cicle after another the values of i and j are redefined... if the break statment is reached, no more for()s should be parsed. Instead of break write return A[i][j]==x.
Basicly it'll be like this:
Code:
int TickTackToe(char A[N][N],int n)
{
int i,j;
for (i=j=0;i<n;i++,j++)//check diagonal up,left->right,down
if (A[i][j]==A[i+1][j+1]==A[i+2][j+2])
return A[i][j]=='x';
for (i=n-1,j=0;i>=0;i--,j++)//check diagonal right,up->down,left
if (A[i][j]==A[i-1][j+1]==A[i-2][j+2])
return A[i][j]=='x';
for(i=0;i<n;i++)//check vertical lines
for(j=0;j<n;j++)
if (A[i][j]==A[i+1][j]==A[i+2][j])
return A[i][j]=='x';
for(j=0;j<n;j++)//check horizontal lines
for(i=0;i<n;i++)
if (A[i][j]==A[i][j+1]==A[i][j+2])
return A[i][j]=='x';
//return statment should have been reached... if not no line was detected
return -1;
}
Hope this one helps.
At the end you had:
if (flag==x)
return (1);
else if (flag==o)
return (0);
return A[i][j]=='x'; does the same stuff: if that char is 'x' return 1, else 0. If no line is detected the function at the end return -1.