'Merging problem when calling same function twice with different parameters in C
i have this piece of code:
void Win_Check(int mat[][MAX], int player, int x1, int y1) {
int check, check2, check3, check4, check5, check6;
check = HorizontalCheck(x1, y1, mat, -1);
check2 = HorizontalCheck(x1, y1, mat, 0);
check3 = VeritcalCheck(x1, y1, mat, -1);
check4 = VeritcalCheck(x1, y1, mat, 0);
check5 = DiagonalCheck(x1, y1, mat, -1);
check6 = DiagonalCheck(x1, y1, mat, 0);
if (check == 1 || check3 == 1 || check5 == 1)
Win_Event(-1, x1, y1, mat);
if (check2 == 1 || check4 == 1 || check6 == 1)
Win_Event(0, x1, y1, mat);
Tie_Check(x1, y1, mat, player);
}
the problem im having is specifically with the lines where i assign check variables to the function DiagonalCheck that function looks like this:
int DiagonalCheck(int x1, int y1, int mat[][MAX], int sign) {
int initialX = 0, initialY, i, j = initialX, CurrentX, Count;
for (j; j < x1;) {
Count = 0;
for (CurrentX = j, initialY = 0; initialY <= y1 - 1; initialY++, CurrentX++) {
if (mat[initialY][CurrentX] == sign)
Count++;
if (mat[initialY][CurrentX] != sign)
Count = 0;
if (Count == 4)
return 1;
printf("%d\n", Count);
}
j++;
}
}
for all of the other functions they work as intended and check things for different parameters but specifically with this function the input from both functions kind of merges. i know solutions to this in other languages but never encouterd it in C before and would like some help in fixing the problem. thanks in advance.
Solution 1:[1]
i finally figured it out what i did was just have 2 signs be entered into the same function and then run the same code inside of the function for each sign and returning 0 at the end of the second outer loop.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Punzicul |
